Re: Last ID

Поиск
Список
Период
Сортировка
От Brett W. McCoy
Тема Re: Last ID
Дата
Msg-id Pine.LNX.4.30.0103021126490.21026-100000@chapelperilous.net
обсуждение исходный текст
Ответ на Last ID  (Catalin CIOCOIU <catalin.ciocoiu@inpg.fr>)
Ответы Re: Last ID  (Tom Lane <tgl@sss.pgh.pa.us>)
RE: Last ID  ("Chuck Kimber" <chuckk@ext.usu.edu>)
Список pgsql-novice
On Fri, 2 Mar 2001, Catalin CIOCOIU wrote:

> How can I get Last ID inserted ???
> The problem is for a multiuser(symultans) database. Exist a statment SQL
> witch get the last id inserted for a session ?

currval('<seq name>') is the way to get the value that was last inserted
into the database.  However, there is no guarantee, in a multiuser
environment, that the value you got was the value you actually used.  You
can also user last_value in an SQL statement, but you still have the
problem of having multiple backends generating sequence values.

A more reliable way is to explicitly call nextval('<seq name>') and use
the value returned to insert into the database.

Please see the CREATE SEQUENCE documentation at
http://www.postgresql.org/users-lounge/docs/7.0/user/sql-createsequence.htm

-- Brett
                                     http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
While my BRAINPAN is being refused service in BURGER KING, Jesuit
priests are DATING CAREER DIPLOMATS!!


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

Предыдущее
От: Catalin CIOCOIU
Дата:
Сообщение: Last ID
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Last ID