Skip to content
Advertisement

PostgreSQL : Selecting all values of a key in jsonb

This is the current code I’m using.

But it’s possible that the jsonb column(agent) contains more than 2 sets of values. Is it possible to write a query without specifying indexing(not including 0,1 in query) and get the result as array_agg using just the key.

Sample jsonb :

My desired output be :

Advertisement

Answer

With Postgres 12 or later, you can use a JSON path query.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement