Skip to content

Instantly share code, notes, and snippets.

@raphox
Created August 3, 2022 19:06
Show Gist options
  • Save raphox/3f3049caf59575bcfb346ba08a9ab562 to your computer and use it in GitHub Desktop.
Save raphox/3f3049caf59575bcfb346ba08a9ab562 to your computer and use it in GitHub Desktop.
copy jsonb data to table row
select agreement_uuid, term->'uuid' from new_agreements
CROSS JOIN LATERAL jsonb_array_elements(royalties_terms) term
where id = 26
create type royalties_terms as (uuid text);
select term.*, agreement_uuid as new_agreement_uuid from new_agreements
CROSS JOIN LATERAL jsonb_populate_recordset(null::agreements_royalty_terms, royalties_terms) term
where id = 26
INSERT INTO agreements_royalty_terms (
uuid,
...
)
SELECT
term.uuid,
...
FROM
new_agreements
CROSS JOIN LATERAL JSONB_POPULATE_RECORDSET(NULL::agreements_royalty_terms, royalties_terms) term
where
id = 26
drop type term_type
select * from pg_type;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment