Re: nextval/dbi question

Поиск
Список
Период
Сортировка
От Horst Herb
Тема Re: nextval/dbi question
Дата
Msg-id 0108060834063F.02026@munin.gnumed.dhs.org
обсуждение исходный текст
Ответ на nextval/dbi question  (harrold@sage.che.pitt.edu)
Ответы Re: nextval/dbi question  (harrold@sage.che.pitt.edu)
Список 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 по дате отправления:

Предыдущее
От: Francisco Reyes
Дата:
Сообщение: Re: select vs varchar
Следующее
От: harrold@sage.che.pitt.edu
Дата:
Сообщение: Re: nextval/dbi question