nextval/dbi question - Mailing list pgsql-novice

From harrold@sage.che.pitt.edu
Subject nextval/dbi question
Date
Msg-id Pine.LNX.4.21.0108051648180.4939-100000@sage.che.pitt.edu
Whole thread Raw
In response to select vs varchar  (Francisco Reyes <lists@natserv.com>)
Responses Re: nextval/dbi question
List pgsql-novice
hey.

i'm using dbi in perl to access a table whos primary key is a serialized
variable. i want to preform an insert on the table and i want the value of
the key associated with that insert.

this is what i'm doing:
# i get the new value like this:
select nextval('testtable_the_key_seq');

#and then i preforme the insert like this:
insert into testtable (an_id, timestamp) values (2, 2);

what results.

say the last value of  the sequence is 'n-1' so the select nextval
statement above will return 'n' but when i preform the insert the value of
testtable.the_key is actually 'n+1'. should i wrap the insert up into a
transaction? any help would be most appreciated.

i dont know if this is relevent but in perl i'm preparing the statement by
using (?,?) and place holders for the (2,2).

thanks
john


pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Indeces vs small tables
Next
From: Francisco Reyes
Date:
Subject: Re: Indeces vs small tables