Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3B7AA47678B for ; Thu, 29 Aug 2002 17:01:10 -0400 (EDT) Received: from vote-smart.org (unknown [12.32.42.180]) by postgresql.org (Postfix) with SMTP id E7661476767 for ; Thu, 29 Aug 2002 17:01:08 -0400 (EDT) Received: (qmail 3779 invoked by uid 1041); 29 Aug 2002 21:05:06 -0000 Received: from clinton@vote-smart.org by eleanor2 by uid 1038 with qmail-scanner-1.10 (hbedv: 6.12.0.0. . Clear:0. Processed in 0.457234 secs); 29 Aug 2002 21:05:06 -0000 Received: from dhcp-216.vote-smart.org (HELO berry.vote-smart.org) (192.168.255.216) by eleanor2.vote-smart.org with SMTP; 29 Aug 2002 21:05:06 -0000 Content-Type: text/plain; charset="iso-8859-1" From: Clinton Adams Reply-To: clinton@vote-smart.org To: Chris Ruprecht , pgsql-php@postgresql.org Subject: Re: How do I get the rec-id from an insert. Date: Thu, 29 Aug 2002 15:00:15 -0600 User-Agent: KMail/1.4.3 References: <200208272340.17513.chris@cdrbill.com> In-Reply-To: <200208272340.17513.chris@cdrbill.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200208291500.15392.clinton@vote-smart.org> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/107 X-Sequence-Number: 1452 Chris - You don't really need to know the key values - make it one query: insert into c values (nextval('crecid'), currval('arecid'), currval('brecid')) On Tue August 27 2002 21:40, Chris Ruprecht graced us with the following - > Hi all, > > I have 3 tables: > > a: > a.recid > a.name > > b: > b.recid > b.address > b.city > > c: > c.recid > c.arecid > c.brecid > > > each has a default sequence on their respective recid - which is the > primary index. > > when I do an "insert into a ...", it automagically assigns recid a new, > unique value, same goes for b. > > But to create c, I need to know the recid from a and b, so I can connect > the two. > Is there any way to get the recid from a and b after they have been > inserted like in "insert into a ... and give me the recid you're going to > use, back"? > > I know, I can do a "netxval('...')" stuff and then insert the records with > values in recid, but that requires two extra calls to the DB per > transaction. > > Best regards, > Chris