Re: nextval/dbi question - Mailing list pgsql-novice

From Horst Herb
Subject Re: nextval/dbi question
Date
Msg-id 0108060834063F.02026@munin.gnumed.dhs.org
Whole thread Raw
In response to nextval/dbi question  (harrold@sage.che.pitt.edu)
Responses Re: nextval/dbi question  (harrold@sage.che.pitt.edu)
List pgsql-novice
On Monday 06 August 2001 06:55, you wrote:

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

you are not assigning it to any variable?

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

I assume that an_id is not your primary key?

> 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).

Why do you call nextval? If your key attribute is "serial", postgres calls
nextval for you autiomatically. Thus, you call it once and postgres calls it
once, hence an increment of 2

Horst

pgsql-novice by date:

Previous
From: Francisco Reyes
Date:
Subject: Re: select vs varchar
Next
From: harrold@sage.che.pitt.edu
Date:
Subject: Re: nextval/dbi question