Re: sequence value of the record just inserted.

Поиск
Список
Период
Сортировка
От Ben Kim
Тема Re: sequence value of the record just inserted.
Дата
Msg-id Pine.GSO.4.10.10404140834220.3753-100000@edsun.coe.tamu.edu
обсуждение исходный текст
Ответ на sequence value of the record just inserted.  (Ben Kim <bkim@coe.tamu.edu>)
Ответы Re: sequence value of the record just inserted.  ("Greg Sabino Mullane" <greg@turnstep.com>)
Список pgsql-admin
Thanks to those who offered help,

The suggested solutions are,
1. Select nextval('myseq'), then use the nextval as the new id to
insert a new record.
2. Insert a new record, then do select currval('myseq') or select last_val
from myseq; supposed to be safe
3. use transaction to guarantee safety

As for solution 2, I wonder what the scope of a "session" is. If I call a
perl subroutine from a web page (the subroutine opens a db handle and
closes it at the end of the subroutine), would it count as one session?
I'll need to check more but would appreciate it if anyone has a ready
advice on this aspect.

Also, in perl DBI, the solutions all require executing at least 2 sql
statements.

I initially hoped there'd be a way to get the oid or sequence number at
the same time as executing an INSERT (one sql statement), like I get oid
in psql. But I use perl DBI, so am not sure how I can get the oid into a
perl variable.

I appreciate the help.


Regards,
Ben Kim



В списке pgsql-admin по дате отправления:

Предыдущее
От: "Donald Fraser"
Дата:
Сообщение: Re: tcl-devel build dependencies for 7.4.2
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: Real time replication of PG DBs accross two servers -