From: | Horst Herb <hherb(at)malleenet(dot)net(dot)au> |
---|---|
To: | harrold(at)sage(dot)che(dot)pitt(dot)edu |
Cc: | Pgsql Novice <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: nextval/dbi question |
Date: | 2001-08-05 22:34:06 |
Message-ID: | 0108060834063F.02026@munin.gnumed.dhs.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | harrold | 2001-08-05 22:47:22 | Re: nextval/dbi question |
Previous Message | Francisco Reyes | 2001-08-05 22:15:45 | Re: select vs varchar |