Created
August 3, 2022 19:06
-
-
Save raphox/3f3049caf59575bcfb346ba08a9ab562 to your computer and use it in GitHub Desktop.
copy jsonb data to table row
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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