Обсуждение: how to get last inserted id

Поиск
Список
Период
Сортировка

how to get last inserted id

От
chris Günther
Дата:
Hi again,

another "stupid" question...

How can I find out the last inserted ID of a field with a serial on it???

    chris

--

Re: how to get last inserted id

От
"Brett W. McCoy"
Дата:
On Fri, 29 Dec 2000, chris Günther wrote:

> How can I find out the last inserted ID of a field with a serial on it???

currval("sequencename");

-- Brett
                                     http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
Cynic, n.:
    Experienced.


Re: how to get last inserted id

От
"Albert REINER"
Дата:
On Fri, Dec 29, 2000 at 12:36:46PM -0500, Brett W. McCoy wrote:
> On Fri, 29 Dec 2000, chris Günther wrote:
>
> > How can I find out the last inserted ID of a field with a serial on it???
>
> currval("sequencename");

currval() will return the last ID inserted from your connection, or
existing before, but without those inserted from other concurrent
connections. This is what you usually want.

But if, for some reason, you are interested just in "what is the last
ID _any_ backend inserted" (which, I think, is the literal meaning of
the question), you will have to look for the maximum value of the
serial field. Usually, though, you should use currval().

Albert.


--

--------------------------------------------------------------------------
Albert Reiner                                   <areiner@tph.tuwien.ac.at>
Deutsch       *       English       *       Esperanto       *       Latine
--------------------------------------------------------------------------