Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fADM7nm53534 for ; Tue, 13 Nov 2001 17:07:50 -0500 (EST) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id fADLs4v36568 for pgsql-sql@postgresql.org; Tue, 13 Nov 2001 16:54:04 -0500 (EST) (envelope-from news) From: "Wilco Boschman" X-Newsgroups: comp.databases.postgresql.sql References: <1f5f2b44.0111130130.17e8e57a@posting.google.com> Subject: Re: INSERT question Date: Tue, 13 Nov 2001 22:51:53 +0100 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Lines: 31 Message-ID: <3bf19679$0$189$e4fe514c@newszilla.xs4all.nl> To: pgsql-sql@postgresql.org X-Archive-Number: 200111/198 X-Sequence-Number: 5582 Insert the row into the parent table (the one with the primary key), then do a select max() from parent_table; This will give you the greatest number in the table, that is if everything went ok the number from the row you just inserted. Then insert the row(s) into the second table and use the value you got from the parent table in the foreign key cheers Wilco "Brian" schreef in bericht news:1f5f2b44.0111130130.17e8e57a@posting.google.com... | Hi everyone, | I've a little question about using insert statements. I've got a | parent table with a "serial" (automatically incrementing integer) | primary key. I have a child table with a foreign key which references | that primary key. My question is: | | To insert values into the child table corresponding to an entry in the | parent table, how do I get a reference to the serial primary key (so | as I can reference it for the foreign key entry) | | Hope you understand what I mean. This should be a regular occurance | and seeing as I'm not an sql guru, I just don't have a clue! | | Any help would be SOOO appreciated. | Brian