AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Cloning a postgres app8/1/2023 cast($3->cloned_row_itr.FIELD::text as bigint) this would use the reference map $3 e.g. The cloning script looks something like drop function if exists clone_stuff() Ĭreate type cloned_stuff_type as (rec Stuff, old_id bigint) Ĭreate or replace function clone_stuff(bigint, bigint, jsonb) returns setof cloned_stuff_type as $$ To that end, I wrote a function that loops over the original rows, inserts them and returns each one mapped as a tuple of record type (here Stuff) with the original id so that the subsequent mapper could have access to the paired old and new id. When cloning Thing rows for a particular app_id, I need the cloned rows to have the stuff_id of the newly cloned Stuff rows, not the old ones. Table Thing (id, app_id, stuff_id, col1, col2. Section two, getting more complicated. The issue is where I have a more complicated table like Thing Now that itself is fine since we don't really need a function (yet). Select NEW_APP_ID, old_stuff_l1, old_stuff_l2 Select * from stuff where app_id = OLD_APP_ID Please ignore things in the following such as capitalized table names etc things like that are merely done for attempted clarity in the reading.įor each table to be able to clone it's rows for a particular app into another, the general idea is with old_stuff_rows as ( I'm currently piecemealing this where each app nested structure clones itself and goes back up. To that end, when I insert the new records, I need to have a reference to the old original primary key (here an id column, bigint) for lots of different tables. I'm working on implementing cloning functionality around an app data structure.
0 Comments
Read More
Leave a Reply. |