Re: [GENERAL] get the previous assigned sequence value

Поиск
Список
Период
Сортировка
От Ed Loehr
Тема Re: [GENERAL] get the previous assigned sequence value
Дата
Msg-id 384F2CE4.115503C@austin.rr.com
обсуждение исходный текст
Ответ на get the previous assigned sequence value  (Kevin Heflin <kheflin@shreve.net>)
Список pgsql-general
Kevin Heflin wrote:

> I've been looking through the online docs, so far have not found this
> information.
>
> After an INSERT, I want to retrieve the value of the sequence I use for
> unique_ids
>
> Any suggestions ?

Use the OID returned from the INSERT to select the newly created value,
i.e.,

    insert into mytable (stuff...) ...
    select id from mytable where oid = NNNN...

How to get the OID in the first example varies depending on your interface
(perl/DBI, PL/pgsql, etc).

Alternatively, use the currval(mytable_id_seq) function within the same
session immediately after the insert.

Cheers.
Ed



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

Предыдущее
От: Thomas Drillich
Дата:
Сообщение: pg_typemgr ;-) [was Re: [GENERAL] no primary key on self designed type]
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: pg_typemgr ;-) [was Re: [GENERAL] no primary key on self designed type]