Skip site navigation (1) Skip section navigation (2)

Re: nextval/dbi question

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: (view raw, whole thread or download thread mbox)
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


In response to


pgsql-novice by date

Next:From: harroldDate: 2001-08-05 22:47:22
Subject: Re: nextval/dbi question
Previous:From: Francisco ReyesDate: 2001-08-05 22:15:45
Subject: Re: select vs varchar

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group