Skip to content

Tag: postgresql

Join two tables with no relation postgres?

I have this statement which you can see I am using Rails and connecting to the database raw, but the output removes duplicate named columns eg user_id etc from the second table and is still giving results in the second table in regards to the first even though there is no relation. Eg There is no relation bet…

Parse text of json object key value postgresql

I have the following kind of objects maintained in a table column. I have tried parsing this object to get the value for this key “1075852262” which has this value “Event=”13″ Description=”(EMOVIES r8)”……….” The SQL I have written is: The resul…

SQL convert rows to one Column

I have a table, Output before pivoting: Expected output: How to do that for three or more rows but always with to one-row column? Answer You can use conditional aggregation: However, I might suggest that you if you want all values in a single row that you just use arrays:

Why `not deferrable` constraint is deferred when using `with`?

When this script is run in PostgreSQL, why does Statement 1 and 2 work and only statement 3 gives an error even when both the foreign key constraint are explicitly not deferrable? Answer According to the docs non-deferrable unique constraints are checked for each row, contrary to the standards specification t…

Postgres Nested JSONB Query

I have a JSONB column, data, in the orders table: I’m trying to select “orders where discount_codes contain a code in codes_array”. I could not figure out how to write this query exactly. I read about the [*] operator but am unsure how to use it in this context. This only searches the first …