Skip to content

Instantly share code, notes, and snippets.

@JonasHeylen
Created February 9, 2017 20:22
Show Gist options
  • Save JonasHeylen/66b1a9a31dce76682837c3fd4d9a468b to your computer and use it in GitHub Desktop.
Save JonasHeylen/66b1a9a31dce76682837c3fd4d9a468b to your computer and use it in GitHub Desktop.
create table json_test(id int primary key, foo jsonb);
insert into json_test values (1, '{"foo": "bar", "xyz": 123}'::jsonb), (2, '{"foo": "qaz", "xyz": 456}'::jsonb);
select id, foo->>'foo' as foo, foo->>'xyz' as xyz from json_test;
select id, x.foo, x.xyz from json_test, jsonb_to_record(foo) as x(foo text, xyz int);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment