Received: from megazone.bigpanda.com ([63.150.15.178]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fAFF3Cm15988 for ; Thu, 15 Nov 2001 10:03:12 -0500 (EST) (envelope-from sszabo@megazone23.bigpanda.com) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id CFCC0D5E6; Thu, 15 Nov 2001 07:03:16 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id C37A15BE4; Thu, 15 Nov 2001 07:03:16 -0800 (PST) Date: Thu, 15 Nov 2001 07:03:16 -0800 (PST) From: Stephan Szabo To: Brian Cc: Subject: Re: INSERT question In-Reply-To: <1f5f2b44.0111130130.17e8e57a@posting.google.com> Message-ID: <20011115070141.P7025-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200111/207 X-Sequence-Number: 5591 On 13 Nov 2001, Brian wrote: > 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! I'd say use select currval(''); Serial is really just a handy wrapper around a sequence and a column default, so I'd suggest reading the docs on sequences.