Multiple inserts with two levels of foreign keys

2023-10-04 Thread Dow Drake
Hi, I'm trying to write a postgresql script to replicate a hierarchical structure in a live database into my development database, where I can debug and test more easily. I can extract the data from the live database that needs to be inserted, but I'm having trouble writing the insertion script

Re: Multiple inserts with two levels of foreign keys

2023-10-08 Thread Dow Drake
Thanks Peter! I'll take a close look at your suggestion when I get a chance. But I've already implemented a Python script that solves my actual problem based on the pattern that Alvaro Herrera suggested for the toy problem I described here. It's working very well to reproduce the farm with

Re: Multiple inserts with two levels of foreign keys

2023-10-05 Thread Dow Drake
Yes! Thanks, Alvaro! This is exactly the pattern I was trying to work out! This community is awesome! > On Oct 5, 2023, at 2:39 AM, Alvaro Herrera wrote: > > On 2023-Oct-04, Dow Drake wrote: > >> I want to insert a farm record, then insert two crops associated

Re: Multiple inserts with two levels of foreign keys

2023-10-04 Thread Dow Drake
of the link in my original post. Best, Dow On Wed, Oct 4, 2023 at 6:26 PM Ron wrote: > Frame challenge: why can't you just "\copy to" the dev database tables in > the correct order, to satisfy foreign key requirements? > > On 10/4/23 18:59, Dow Drake wrote: > >

Re: Multiple inserts with two levels of foreign keys

2023-10-04 Thread Dow Drake
wrote: > Ah. We'd truncate all of the dev tables, then load a "slice" (for > example, accounts 1 to 1, and all associated records from > downstream tables; lots and lots of views!!) from the prod database. > > On 10/4/23 20:50, Dow Drake wrote: > > Thanks for t