Received: from stine.vestdata.no (IDENT:1002@stine.vestdata.no [195.204.68.10]) by hub.org (8.9.3/8.9.3) with ESMTP id DAA53767 for ; Sat, 27 May 2000 03:32:26 -0400 (EDT) (envelope-from ragnark@stine.vestdata.no) Received: (from ragnark@localhost) by stine.vestdata.no (8.9.3/8.9.1) id JAA30087; Sat, 27 May 2000 09:32:11 +0200 Date: Sat, 27 May 2000 09:32:10 +0200 From: =?iso-8859-1?Q?Ragnar_Kj=F8rstad?= To: Peter Eisentraut Cc: Rainer Mager , pgsql-admin@postgresql.org Subject: Re: A few misc. questions. Message-ID: <20000527093210.B29792@vestdata.no> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 0.95.5i In-Reply-To: ; from Peter Eisentraut on Fri, May 26, 2000 at 04:15:31PM +0200 X-Archive-Number: 200005/43 On Fri, May 26, 2000 at 04:15:31PM +0200, Peter Eisentraut wrote: > On Fri, 26 May 2000, Rainer Mager wrote: > > > 2. Does anyone one know a standard SQL method (that works with Postgres) to > > retrieve the primary key of a newly INSERTed record? We've found one way but > > it will not work with order databases since it relies on reading data from > > the sequence tables. > > Again, what you do with your primary keys is up to you. Ideally you won't > need to retrieve the primary key value because you know what you just > inserted. If you are talking about serial, then the answer is there isn't > one because serial isn't SQL. But as someone already said, the curval > function will do. Another approach is something like this: pkey=sql("select nextval('some-sequence')") sql("insert into table values ($pkey, $data)") -- Ragnar Kjørstad