pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Charles Hauser <chauser@duke.edu>
To: pgsql-sql@postgresql.org
Subject: problem fetching currval of sequence
Date: Tue, 6 Aug 2002 11:14:49 -0400
Message-ID: <a05111b00b97594e67c38@[152.3.11.193]> (raw)

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

view thread (12+ messages)  latest in thread

Message-ID: <a05111b00b97594e67c38@[152.3.11.193]>
Permalink:  ../a05111b00b97594e67c38@%5B152.3.11.193%5D/
Also on:    postgresql.org/message-id/a05111b00b97594e67c38@[152.3.11.193]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chauser@duke.edu
  Subject: Re: problem fetching currval of sequence
  In-Reply-To: <a05111b00b97594e67c38@[152.3.11.193]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox