Skip to content

Tag: postgresql

LEFT JOIN ON string match Very slow

I have to perform this LEFT JOIN but it’s very slow (30.000ms) because of the match on text string. How can I make it faster? SELECT * FROM table_a LEFT JOIN table_b ON ( table_b.state = ‘…

Query for array values within jsonb column

I have a jsonb column called chores in my work table with data looking something like this: [{“task”: “feed_dog”, “value”: “Daily”},{“task”: “mop_floor”, “value”: “Weekly”] There could be zero to dozens of tasks in…

Postgres Compare string to number return correct result

Trying to understand how postgres compare string to number because following queries return true, Can someone please explain? Answer PostgreSQL applies implicit conversion where necessary and possible. How it does this is no further explained as far as I know. (https://www.postgresql.org/docs/9.1/typeconv.htm…

Postgres get root of self-referential table

Given the table: If I get a name from the table (and thus the Pkey), how can I get the name of it’s “root”-level parent: the name where parent is NULL which is referenced to (indirectly) by the given name. Say I have these values (I don’t know which values I will get): The function/wha…