> So... not really an answer (other than I used a stored proc) Actually, I'm interested in your solution. Just to make sure I understood what you did: you bulk-populated (i.e. with $dbh->do('COPY...'), $dbh->pg_putline(...), $dbh->pg_endcopy) the referring tables, with their fkey constraints disabled; then you ran stored procedure(s) that went through these referring tables and filled in the missing fkeys; and finally you activated their fkey constraints. Is this right? I'm very much of a stored procedures dunce, so if the code for your stored procedure is "postable", please do. TIA, kj PS: As an aside to the list, as a programmer, when I'm starting out in language, I learn more than I can say from reading source code written by the experts, but for some reason I have had a hard time coming across expertly written PostgreSQL stored procedures, other than the occasionally didactic snippet in the docs. All these expertly-written procedures seem to be very STORED away indeed! If, on the contrary, it's just the case that I haven't looked in the right places, please hurl me a cluebrick! ---------------------------(end of broadcast)--------------------------- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your message can get through to the mailing list cleanly