Skip to content

Tag: postgresql

PostgreSql format jsonb array

Can not find a proper query to format jsonb output in postgres I have a jonb column in a table. How do I select the posts column to have just certain fields? Something like: Any ideas? PS: The version of postgres is the latest 12, 13, 14 … Answer You may considering using json_to_record_set to extract y…

Select based on group membership

Suppose I have two tables t and o. I want to select all the rows of t in which t.feature = o.feature (ergo first two rows). In addition, I also want to select all the rows whose t.grouping = t.grouping of the previously selected rows. In this case t.grouping 1, 2 ergo rows (‘E’, 1), (‘F&#821…

Selecting and comparing columns which contain constants

Follow up to this question. Say that on postgres, I have a table TABLE1 containing the columns id (integer), name (string): And attempt to run the following queries: On sqlfiddle, the former yields a result, whilst the latter fails with the message: On postgres 13.3 which I have installed locally, however, ne…

JSON array to a single row in SQL table

I have a table in PostgreSQL database. With some data in it: receipt column contains lists of 3-element lists. What I’m trying to achieve is write an SQL query that returns table in the form The best I’ve got so far is but I’m stuck on unnesting the inner arrays. I tried using jsonb_to_recor…