X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 7F53331030B for ; Fri, 27 Jun 2003 21:49:51 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 44142-03 for ; Fri, 27 Jun 2003 18:49:41 -0300 (ADT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id 85BDB310385 for ; Fri, 27 Jun 2003 18:49:40 -0300 (ADT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h5RLlxA0018423; Fri, 27 Jun 2003 15:48:00 -0600 (MDT) Date: Fri, 27 Jun 2003 15:42:45 -0600 (MDT) From: "scott.marlowe" To: Michael Kovalcik Cc: Josh Goldberg , Bruno Wolff III , Subject: Re: How do I select the last Id in a column??? In-Reply-To: <20030627213130.17702.qmail@web11106.mail.yahoo.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Archive-Number: 200306/330 X-Sequence-Number: 9321 Note that that has race conditions, i.e. two clients operating at the same time could get the same max(id). The setval currval and nextval functions exist to prevent race conditions, and they work well. Rolling your own is a recipe for disaster. On Fri, 27 Jun 2003, Michael Kovalcik wrote: > All, > > i got the answer i was needing. I used the following: > > select max(id) from table > > it works great!! :) > > --- Josh Goldberg wrote: > > What could cause a table to act serialized when read > > committed transactions > > are set in the configuration? That is something I > > am running into, which > > provoked my [incorrect] example. > > > > From: "Bruno Wolff III" > > Sent: Thursday, June 26, 2003 4:30 PM > > > On Thu, Jun 26, 2003 at 14:00:33 -0700, > > > Josh Goldberg wrote: > > > > to get the last record inserted just > > > > select * from row order by autoincId desc limit > > 1; > > > > > > > > if you have several clients doing this you might > > want to put your insert > > and > > > > the select inside a transaction. > > > > > > That won't help. Your suggestion will only work in > > serializable > > transactions. > > > > > > In read committed mode the select might see a > > value for autoincId from > > > a transaction that committed between the insert > > and the select. > > > > > > ---------------------------(end of > > broadcast)--------------------------- > > > TIP 8: explain analyze is your friend > > > > > > > > __________________________________ > Do you Yahoo!? > SBC Yahoo! DSL - Now only $29.95 per month! > http://sbc.yahoo.com > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >