Skip to content

Instantly share code, notes, and snippets.

@martinusso
Created June 30, 2023 20:18
Show Gist options
  • Save martinusso/2dd3e200518218637735f29fc0eba76c to your computer and use it in GitHub Desktop.
Save martinusso/2dd3e200518218637735f29fc0eba76c to your computer and use it in GitHub Desktop.
postgres jsonb
-- {"1": [{"id": 1,"name": "Max"},{"id": 11,"name": "Perez"}],"2": [{"id": 2,"name": "Leclerc"},{"id": 3,"name": "Sainz"}]}
select
j.*
from test,
jsonb_each(metadata) as j
select
jsonb_each(metadata)
from test
with a as (
select
key as k,
jsonb_array_elements(value) as v
from test,
jsonb_each(metadata) as j
)
select * from a
where v->>'name' = 'Max'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment