Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id AA825475820 for ; Tue, 6 Aug 2002 16:18:48 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 1D6094757AF for ; Tue, 6 Aug 2002 16:18:48 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id g76KIjVk002972; Tue, 6 Aug 2002 16:18:45 -0400 (EDT) To: josh@agliodbs.com Cc: Charles Hauser , pgsql-sql@postgresql.org Subject: Re: problem fetching currval of sequence In-reply-to: <200208061135.20799.josh@agliodbs.com> References: <20611.1028651144@sss.pgh.pa.us> <200208061135.20799.josh@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Tue, 06 Aug 2002 11:35:20 -0700" Date: Tue, 06 Aug 2002 16:18:45 -0400 Message-ID: <2971.1028665125@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/115 X-Sequence-Number: 8961 Josh Berkus writes: > No, back in 7.1.0 I was able to call CURRVAL without having previously > called NEXTVAL, and it would give me the "current" sequence value; > that is, the same result value as (NEXTVAL() - 1) I don't believe it, and neither do the 7.1.3 and 7.0.2 databases that I have handy to check with. For example: play=> select version(); version ------------------------------------------------------------------ PostgreSQL 7.0.2 on hppa2.0-hp-hpux10.20, compiled by gcc 2.95.2 (1 row) play=> create sequence seq; CREATE play=> select currval('seq'); ERROR: seq.currval is not yet defined in this session play=> select nextval('seq'); nextval --------- 1 (1 row) play=> select currval('seq'); currval --------- 1 (1 row) play=> \c play You are now connected to database play. play=> select currval('seq'); ERROR: seq.currval is not yet defined in this session Are you sure you were not thinking of "select last_value from seq"? That's about the closest approximation I can think of to a non-transaction-safe version of currval(). regards, tom lane