From chauser@duke.edu Tue Aug 6 15:13:15 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id BBF70476265 for ; Tue, 6 Aug 2002 11:13:15 -0400 (EDT) Received: from eddings.acpub.duke.edu (eddings.acpub.duke.edu [152.3.233.76]) by postgresql.org (Postfix) with ESMTP id 1272F476233 for ; Tue, 6 Aug 2002 11:13:15 -0400 (EDT) Received: from [152.3.11.193] (bglab2.botany.duke.edu [152.3.11.193]) by eddings.acpub.duke.edu (8.12.4/8.12.4/Duke-5.0.0) with ESMTP id g76FDGZ2010465; Tue, 6 Aug 2002 11:13:17 -0400 (EDT) Mime-Version: 1.0 X-Sender: chauser@mail-ch.acpub.duke.edu Message-Id: Date: Tue, 6 Aug 2002 11:14:49 -0400 To: pgsql-sql@postgresql.org From: Charles Hauser Subject: problem fetching currval of sequence Content-Type: multipart/alternative; boundary="============_-1183475592==_ma============" X-Virus-Scanned: by amavisd-milter, Duke University (http://amavis.org/) X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/92 X-Sequence-Number: 8938 --============_-1183475592==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" Hi, I have a script to load values into a table (gb) which contains a SEQUENCE ('gb_id'). For each entry into TABLE gb I need the value of 'gb_gb_id_seq' to update a relational table. I am getting the following error msg: ERROR: gb_gb_id_seq.currval is not yet defined in this session. If anyone knows why this is not working I would appreciate suggestions. CREATE TABLE "gb" ( "gb_id" int4 DEFAULT nextval('"gb_gb_id_seq"'::text) NOT NULL, "clone_id" int4, "accn" varchar(12) NOT NULL, "gi" int4 NOT NULL, CONSTRAINT "gb_pkey" PRIMARY KEY ("gb_id") ); foreach $id(sort keys %ACCN) { $conn->exec( "UPDATE gb SET accn_no = '$ACCN{$id}{gb}',gi_no = '$ACCN{$id}{gi}' WHERE clone_id = '$ACCN{$id}{clone_id}'" ); $result = $conn->exec("SELECT currval('gb_gb_id_seq');"); die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus; $gb_id = $result->fetchrow; $ACCN{$id}{gb_id} = $gb_id; } -- Regards, Charles --============_-1183475592==_ma============ Content-Type: text/html; charset="us-ascii" problem fetching currval of sequence
Hi,

I have a script to load values into a table (gb) which contains a SEQUENCE ('gb_id').  For each entry into TABLE gb I need the value of 'gb_gb_id_seq' to update a relational table.   I am getting the following error msg:
                ERROR: gb_gb_id_seq.currval is not yet defined in this session.

If anyone knows why this is not working I would appreciate suggestions.



CREATE TABLE "gb" (
   "gb_id" int4 DEFAULT nextval('"gb_gb_id_seq"'::text) NOT NULL,
   "clone_id" int4,
   "accn" varchar(12) NOT NULL,
   "gi" int4 NOT NULL,
   CONSTRAINT "gb_pkey" PRIMARY KEY ("gb_id")
);

    foreach $id(sort keys %ACCN) {
      $conn->exec(
                   "UPDATE gb SET accn_no = '$ACCN{$id}{gb}',gi_no = '$ACCN{$id}{gi}' WHERE clone_id = '$ACCN{$id}{clone_id}'"
                   );

        $result = $conn->exec("SELECT currval('gb_gb_id_seq');");
        die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus;
        $gb_id = $result->fetchrow;
        $ACCN{$id}{gb_id} = $gb_id;
    }

-- 
Regards,

        Charles
--============_-1183475592==_ma============-- From josh@agliodbs.com Tue Aug 6 15:45:43 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A38DF475820 for ; Tue, 6 Aug 2002 11:45:43 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 08678475813 for ; Tue, 6 Aug 2002 11:45:43 -0400 (EDT) Received: from [63.195.55.98] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.5.9) with HTTP id 1602018; Tue, 06 Aug 2002 08:45:45 -0700 From: "Josh Berkus" Subject: Re: problem fetching currval of sequence To: Charles Hauser , pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.5.9 Date: Tue, 06 Aug 2002 08:45:45 -0700 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/94 X-Sequence-Number: 8940 Charles, > I have a script to load values into a table (gb) which contains a > SEQUENCE ('gb_id'). For each entry into TABLE gb I need the value of > 'gb_gb_id_seq' to update a relational table. I am getting the > following error msg: > ERROR: gb_gb_id_seq.currval is not yet defined in this session. Sometime in the upgrade process for 7.1.0 --> 7.2.1, the CURRVAL function changed so that it was rigorously session-specific. I can see a number of good reasons for doing this, but it has the unfortunate side effect that CURRVAL is virtually useless for querying the current value of the row you just inserted using a front-end that creates a new session for each command. I'd love to hear Tom, Bruce, or Stephan's comments on the issue. It is an annoyance, and it would be nice to know the reason for the decrease in functionality of CURRVAL. All that aside, the first query you are sending to Postgres is an UPDATE query, not an INSERT. So what good was CURRVAL going to do you anyway? -Josh Berkus From sszabo@megazone23.bigpanda.com Tue Aug 6 15:57:40 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7063E4758C0 for ; Tue, 6 Aug 2002 11:57:40 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id C7D62475833 for ; Tue, 6 Aug 2002 11:57:39 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id BC157D606; Tue, 6 Aug 2002 08:57:41 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id B1C8E5C03; Tue, 6 Aug 2002 08:57:41 -0700 (PDT) Date: Tue, 6 Aug 2002 08:57:41 -0700 (PDT) From: Stephan Szabo To: Josh Berkus Cc: Charles Hauser , Subject: Re: problem fetching currval of sequence In-Reply-To: Message-ID: <20020806084817.M83826-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/95 X-Sequence-Number: 8941 On Tue, 6 Aug 2002, Josh Berkus wrote: > Charles, > > > I have a script to load values into a table (gb) which contains a > > SEQUENCE ('gb_id'). For each entry into TABLE gb I need the value of > > 'gb_gb_id_seq' to update a relational table. I am getting the > > following error msg: > > ERROR: gb_gb_id_seq.currval is not yet defined in this session. > > Sometime in the upgrade process for 7.1.0 --> 7.2.1, the CURRVAL > function changed so that it was rigorously session-specific. I can see > a number of good reasons for doing this, but it has the unfortunate > side effect that CURRVAL is virtually useless for querying the current > value of the row you just inserted using a front-end that creates a new > session for each command. > > I'd love to hear Tom, Bruce, or Stephan's comments on the issue. It is > an annoyance, and it would be nice to know the reason for the decrease > in functionality of CURRVAL. Presumably because it was fairly useless the other way? I must be missing how it worked. I can't see what you could do with the value apart from getting a value that was at one point the most recent value of the sequence, but a random number up to its current value in its range would do the same thing. ;) It doesn't guarantee you that you can see a row with that value (in the case of the default) - or even if such a row will ever exist, it doesn't guarantee you that it's really the last row (since nextval could be called after the value is gotten but before your query results are returned. If you're doing an insert in one session, closing the session, and starting a new one wanting to know the insert value from the previous one, I don't see how currval helps, it'll give you *a* most recent value, but not necessarily yours (unless you only have one updating session, in which case you don't really need a sequence since you don't need the concurrency guarantees). From tgl@sss.pgh.pa.us Tue Aug 6 16:16:53 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id B51874762DC for ; Tue, 6 Aug 2002 12:16:53 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id DA1EF4761E0 for ; Tue, 6 Aug 2002 12:16: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 g76GGVVk020534; Tue, 6 Aug 2002 12:16:31 -0400 (EDT) To: Charles Hauser Cc: pgsql-sql@postgresql.org Subject: Re: problem fetching currval of sequence In-reply-to: References: Comments: In-reply-to Charles Hauser message dated "Tue, 06 Aug 2002 11:14:49 -0400" Date: Tue, 06 Aug 2002 12:16:30 -0400 Message-ID: <20533.1028650590@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/97 X-Sequence-Number: 8943 Charles Hauser writes: > foreach $id(sort keys %ACCN) { > $conn->exec( > "UPDATE gb SET accn_no = '$ACCN{$id}{gb}',gi_no = > '$ACCN{$id}{gi}' WHERE clone_id = '$ACCN{$id}{clone_id}'" > ); > $result = $conn->exec("SELECT currval('gb_gb_id_seq');"); This isn't inserting any new row, so nextval() isn't called, so there's nothing for currval() to work on. Are you sure you did not mean to do an INSERT? If you did want an UPDATE, seems like you could do SELECT gb_id FROM gb WHERE clone_id = '$ACCN{$id}{clone_id}' regards, tom lane From tgl@sss.pgh.pa.us Tue Aug 6 16:29:32 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 67DB4475820 for ; Tue, 6 Aug 2002 12:29:32 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id C8315475813 for ; Tue, 6 Aug 2002 12:29:31 -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 g76GPiVk020612; Tue, 6 Aug 2002 12:25:44 -0400 (EDT) To: "Josh Berkus" Cc: Charles Hauser , pgsql-sql@postgresql.org Subject: Re: problem fetching currval of sequence In-reply-to: References: Comments: In-reply-to "Josh Berkus" message dated "Tue, 06 Aug 2002 08:45:45 -0700" Date: Tue, 06 Aug 2002 12:25:44 -0400 Message-ID: <20611.1028651144@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/98 X-Sequence-Number: 8944 "Josh Berkus" writes: > Sometime in the upgrade process for 7.1.0 --> 7.2.1, the CURRVAL > function changed so that it was rigorously session-specific. Huh? AFAIR it's always worked the way it does now (and a quick review of the CVS logs for sequence.c backs up my recollection). > ... it has the unfortunate > side effect that CURRVAL is virtually useless for querying the current > value of the row you just inserted using a front-end that creates a new > session for each command. Such a front end would be too broken to consider using anyway: if you cannot wrap several related commands into a transaction, you cannot use a database the way it's intended to be used. The connection-pooling front ends that I know about all give you dedicated use of a connection for at least the length of a transaction block, so the secret to using currval is "do it in the same transaction block as you call nextval in". regards, tom lane From chauser@duke.edu Tue Aug 6 16:42:01 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 9482A475FB0 for ; Tue, 6 Aug 2002 12:42:01 -0400 (EDT) Received: from wilson.acpub.duke.edu (wilson.acpub.duke.edu [152.3.233.69]) by postgresql.org (Postfix) with ESMTP id 7193B475993 for ; Tue, 6 Aug 2002 12:41:55 -0400 (EDT) Received: from [152.3.11.193] (bglab2.botany.duke.edu [152.3.11.193]) by wilson.acpub.duke.edu (8.12.4/8.12.4/Duke-5.0.0) with ESMTP id g76GfwEc015812; Tue, 6 Aug 2002 12:41:59 -0400 (EDT) Mime-Version: 1.0 X-Sender: chauser@mail-ch.acpub.duke.edu Message-Id: In-Reply-To: <20533.1028650590@sss.pgh.pa.us> References: <20533.1028650590@sss.pgh.pa.us> Date: Tue, 6 Aug 2002 12:43:32 -0400 To: Tom Lane From: Charles Hauser Subject: Re: problem fetching currval of sequence Cc: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary="============_-1183470269==_ma============" X-Virus-Scanned: by amavisd-milter, Duke University (http://amavis.org/) X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/106 X-Sequence-Number: 8952 --============_-1183470269==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" Tom, Quite right, I did mean to do an INSERT. Changing the script to do so though I still get the error: ERROR: gb_gb_id_seq.currval is not yet defined in this session. foreach $id(sort keys %ACCN) { $conn->exec( "INSERT INTO gb (clone_id,accn,gi) VALUES ( '$ACCN{$id}{clone_id}','$ACCN{$id}{gb}','$ACCN{$id}{gi}')"; ); $result = $conn->exec("SELECT currval('gb_gb_id_seq');"); die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus; $gb_id = $result->fetchrow; $ACCN{$id}{gb_id} = $gb_id; } >Charles Hauser writes: >> foreach $id(sort keys %ACCN) { >> $conn->exec( >> "UPDATE gb SET accn_no = '$ACCN{$id}{gb}',gi_no = >> '$ACCN{$id}{gi}' WHERE clone_id = '$ACCN{$id}{clone_id}'" >> ); > >> $result = $conn->exec("SELECT currval('gb_gb_id_seq');"); > >This isn't inserting any new row, so nextval() isn't called, so there's >nothing for currval() to work on. Are you sure you did not mean to do >an INSERT? > >If you did want an UPDATE, seems like you could do > > SELECT gb_id FROM gb WHERE clone_id = '$ACCN{$id}{clone_id}' > > regards, tom lane -- Regards, Chuck --============_-1183470269==_ma============ Content-Type: text/html; charset="us-ascii" Re: [SQL] problem fetching currval of sequence
Tom,

Quite right, I did mean to do an INSERT.  Changing the script to do so though I still get the error:
                ERROR: gb_gb_id_seq.currval is not yet defined in this session.


    foreach $id(sort keys %ACCN) {
      $conn->exec(
                                "INSERT INTO gb (clone_id,accn,gi) VALUES ( '$ACCN{$id}{clone_id}','$ACCN{$id}{gb}','$ACCN{$id}{gi}')";
                                );
        $result = $conn->exec("SELECT currval('gb_gb_id_seq');");
        die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus;
        $gb_id = $result->fetchrow;
        $ACCN{$id}{gb_id} = $gb_id;
    }


Charles Hauser <chauser@duke.edu> writes:
>      foreach $id(sort keys %ACCN) {
> $conn->exec(
>                     "UPDATE gb SET accn_no = '$ACCN{$id}{gb}',gi_no =
> '$ACCN{$id}{gi}' WHERE clone_id = '$ACCN{$id}{clone_id}'"
>                     );

> $result = $conn->exec("SELECT currval('gb_gb_id_seq');");

This isn't inserting any new row, so nextval() isn't called, so there's
nothing for currval() to work on.  Are you sure you did not mean to do
an INSERT?

If you did want an UPDATE, seems like you could do

      SELECT gb_id FROM gb WHERE clone_id = '$ACCN{$id}{clone_id}'

                    regards, tom lane


-- 
Regards,

        Chuck
--============_-1183470269==_ma============-- From tgl@sss.pgh.pa.us Tue Aug 6 16:48:29 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 91B9947595D for ; Tue, 6 Aug 2002 12:48:29 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id E5542475947 for ; Tue, 6 Aug 2002 12:48:28 -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 g76GmWVk020829; Tue, 6 Aug 2002 12:48:32 -0400 (EDT) To: Charles Hauser Cc: pgsql-sql@postgresql.org Subject: Re: problem fetching currval of sequence In-reply-to: References: <20533.1028650590@sss.pgh.pa.us> Comments: In-reply-to Charles Hauser message dated "Tue, 06 Aug 2002 12:43:32 -0400" Date: Tue, 06 Aug 2002 12:48:32 -0400 Message-ID: <20828.1028652512@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/107 X-Sequence-Number: 8953 Charles Hauser writes: > Quite right, I did mean to do an INSERT. Changing the script to do > so though I still get the error: > ERROR: gb_gb_id_seq.currval is not yet defined in this session. > foreach $id(sort keys %ACCN) { > $conn->exec( > "INSERT INTO gb (clone_id,accn,gi) > VALUES ( '$ACCN{$id}{clone_id}','$ACCN{$id}{gb}','$ACCN{$id}{gi}')"; > ); > $result = $conn->exec("SELECT currval('gb_gb_id_seq');"); > die $conn->errorMessage unless PGRES_TUPLES_OK eq > $result->resultStatus; > $gb_id = $result->fetchrow; > $ACCN{$id}{gb_id} = $gb_id; > } Hmm, that sure looks like it should work. I can only counsel looking for silly errors (typos, not running the same copy of the script that you edited, etc). Also double-check that gb.gb_id has the column default nextval('gb_gb_id_seq') (try psql's "\d gb" command). regards, tom lane From josh@agliodbs.com Tue Aug 6 18:34:16 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4086F4759D8 for ; Tue, 6 Aug 2002 14:34:16 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 369FE475835 for ; Tue, 6 Aug 2002 14:34:15 -0400 (EDT) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 1602326; Tue, 06 Aug 2002 11:34:14 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Tom Lane Subject: Re: problem fetching currval of sequence Date: Tue, 6 Aug 2002 11:35:20 -0700 X-Mailer: KMail [version 1.4] Cc: Charles Hauser , pgsql-sql@postgresql.org References: <20611.1028651144@sss.pgh.pa.us> In-Reply-To: <20611.1028651144@sss.pgh.pa.us> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200208061135.20799.josh@agliodbs.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/114 X-Sequence-Number: 8960 Tom, > Huh? AFAIR it's always worked the way it does now (and a quick review > of the CVS logs for sequence.c backs up my recollection). No, back in 7.1.0 I was able to call CURRVAL without having previously call= ed=20 NEXTVAL, and it would give me the "current" sequence value; that is, the sa= me=20 result value as (NEXTVAL() - 1); I wouldn't mind having a new function th= at=20 does this; I can understand making a distinction between the pre-session=20 CURRVAL, and the general current value. > Such a front end would be too broken to consider using anyway: if you > cannot wrap several related commands into a transaction, you cannot use > a database the way it's intended to be used. The connection-pooling > front ends that I know about all give you dedicated use of a connection > for at least the length of a transaction block, so the secret to using > currval is "do it in the same transaction block as you call nextval in". Me, I use functions. --=20 -Josh Berkus Aglio Database Solutions San Francisco From tgl@sss.pgh.pa.us Tue Aug 6 20:18:48 2002 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 From josh@agliodbs.com Tue Aug 6 20:36:41 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E872E475820 for ; Tue, 6 Aug 2002 16:36:41 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 622F7474E49 for ; Tue, 6 Aug 2002 16:36:41 -0400 (EDT) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 1602568; Tue, 06 Aug 2002 13:36:41 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Tom Lane Subject: Re: problem fetching currval of sequence Date: Tue, 6 Aug 2002 13:37:48 -0700 X-Mailer: KMail [version 1.4] Cc: Charles Hauser , pgsql-sql@postgresql.org References: <200208061135.20799.josh@agliodbs.com> <2971.1028665125@sss.pgh.pa.us> In-Reply-To: <2971.1028665125@sss.pgh.pa.us> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200208061337.48357.josh@agliodbs.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/116 X-Sequence-Number: 8962 Tom, > 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(). Well, you are the authority. And I'm not willing to regress my database= =20 install just to figure it out. Maybe I am thinking of "Select last_value". --=20 -Josh Berkus ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco From chauser@duke.edu Tue Aug 6 20:51:53 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 863CC47580D for ; Tue, 6 Aug 2002 16:51:53 -0400 (EDT) Received: from wilson.acpub.duke.edu (wilson.acpub.duke.edu [152.3.233.69]) by postgresql.org (Postfix) with ESMTP id E435E475809 for ; Tue, 6 Aug 2002 16:51:52 -0400 (EDT) Received: from [152.3.11.193] (bglab2.botany.duke.edu [152.3.11.193]) by wilson.acpub.duke.edu (8.12.4/8.12.4/Duke-5.0.0) with ESMTP id g76KpkEc009696; Tue, 6 Aug 2002 16:51:50 -0400 (EDT) Mime-Version: 1.0 X-Sender: chauser@mail-ch.acpub.duke.edu Message-Id: In-Reply-To: <200208061135.20799.josh@agliodbs.com> References: <20611.1028651144@sss.pgh.pa.us> <200208061135.20799.josh@agliodbs.com> Date: Tue, 6 Aug 2002 16:53:24 -0400 To: josh@agliodbs.com From: Charles Hauser Subject: Re: problem fetching currval of sequence Cc: pgsql-sql@postgresql.org, tgl@sss.pgh.pa.us Content-Type: multipart/alternative; boundary="============_-1183455277==_ma============" X-Virus-Scanned: by amavisd-milter, Duke University (http://amavis.org/) X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/117 X-Sequence-Number: 8963 --============_-1183455277==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" Josh and Tom, I have checked for typos, rewritten a smaller script and checked the table setup (\d gb, see below) and $result = $conn->exec( "SELECT currval('gb_gb_id_seq');" ); continues to return the error: ERROR: gb_gb_id_seq.currval is not yet defined in this session I know this script worked in the past, but I have not used it recently. We are running PostgreSQL 7.1.3. It would be great if this would work as I have several scripts which operate in a similar manner for different TABLES, but if it won't work I'll work around it. Suggestions for the best way to get the value for the gb_id after an INSERT? chlamy_est=> \d gb Table "gb" Attribute | Type | Modifier -----------+-----------------------+-------------------------------------------------- gb_id | integer | not null default nextval('"gb_gb_id_seq"'::text) clone_id | integer | accn | character varying(12) | not null gi | integer | not null Index: gb_pkey Hmm, that sure looks like it should work. I can only counsel looking for silly errors (typos, not running the same copy of the script that you edited, etc). Also double-check that gb.gb_id has the column default nextval('gb_gb_id_seq') (try psql's "\d gb" command). -- Regards, Chuck --============_-1183455277==_ma============ Content-Type: text/html; charset="us-ascii" Re: [SQL] problem fetching currval of sequence
Josh and Tom,

I have checked for typos, rewritten a smaller script and checked the table setup (\d gb, see below) and
        $result = $conn->exec(
                        "SELECT currval('gb_gb_id_seq');"
                          );

continues to return the error:

        ERROR:  gb_gb_id_seq.currval is not yet defined in this session

I know this script worked in the past, but I have not used it recently.  We are running PostgreSQL 7.1.3.  It would be great if this would work as I have several scripts which operate in a similar manner for different TABLES, but if it won't work I'll work around it.

Suggestions for the best way to get the value for the gb_id after an INSERT?



chlamy_est=> \d gb
                                      Table "gb"
 Attribute |         Type          |                     Modifier                    
-----------+-----------------------+--------------------------------------------------
 gb_id     | integer               | not null default nextval('"gb_gb_id_seq"'::text)
 clone_id  | integer               |
 accn      | character varying(12) | not null
 gi        | integer               | not null
Index: gb_pkey

Hmm, that sure looks like it should work.  I can only counsel looking
for silly errors (typos, not running the same copy of the script that you
edited, etc).  Also double-check that gb.gb_id has the column default
nextval('gb_gb_id_seq')  (try psql's "\d gb" command).


-- 
Regards,

        Chuck
--============_-1183455277==_ma============-- From josh@agliodbs.com Tue Aug 6 21:25:51 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 8366C474E49 for ; Tue, 6 Aug 2002 17:25:51 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id E2897474E44 for ; Tue, 6 Aug 2002 17:25:50 -0400 (EDT) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 1602661; Tue, 06 Aug 2002 14:25:50 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Charles Hauser Subject: Re: problem fetching currval of sequence Date: Tue, 6 Aug 2002 14:26:58 -0700 X-Mailer: KMail [version 1.4] References: <200208061135.20799.josh@agliodbs.com> In-Reply-To: Cc: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200208061426.58011.josh@agliodbs.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/118 X-Sequence-Number: 8964 Charles, > I know this script worked in the past, but I have not used it=20 > recently. We are running PostgreSQL 7.1.3. It would be great if=20 > this would work as I have several scripts which operate in a similar=20 > manner for different TABLES, but if it won't work I'll work around it. >=20 > Suggestions for the best way to get the value for the gb_id after an INSE= RT? I usually SELECT NEXTVAL(), and then pass that ID number to the INSERT=20 statement. It's very reliable. --=20 -Josh Berkus ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco