Re: get last sequence

Поиск
Список
Период
Сортировка
От Oliver Elphick
Тема Re: get last sequence
Дата
Msg-id 200101271005.f0RA5LF23566@linda.lfix.co.uk
обсуждение исходный текст
Ответ на get last sequence  ("Mr. Chan" <daatmor@hongkong.com>)
Список pgsql-general
"Mr. Chan" wrote:
  >dear all,
  >    how to get last sequence from postgresql? I mean such mysql
  >last_insert_id function or ms sql select @@identity.

I presume you mean get the last value assigned by the sequence.
If the sequence has been used in the current session (since connecting
to the backend) you can use the function currval('sequence_name').
this ignores any value issued to other users, so it is always safe
to use.

You cannot use currval if the sequence has not yet been used in the
session.

junk=# select currval('a_a_seq');
ERROR:  a_a_seq.currval is not yet defined in this session

junk=# insert into a (b) values ('garbage');
INSERT 6821792 1

junk=# select currval('a_a_seq');
 currval
---------
       4
(1 row)


--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "Come now, and let us reason together, saith the LORD;
      though your sins be as scarlet, they shall be as white
      as snow; though they be red like crimson, they shall
      be as wool."                     Isaiah 1:18



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

Предыдущее
От: Marc SCHAEFER
Дата:
Сообщение: Re: Re: Problem with inheritance
Следующее
От: "Oliver Elphick"
Дата:
Сообщение: Re: Wild Cards