Re: Get last serial (autoincrement) value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



At 06:34 AM 9/1/03, aka MacGuru wrote:
Anyone knows how to obtain last inserted serial (autoincrement) id? I am currently using "SELECT id FROM table_name ORDER BY id DESC", and then retrieve first row and desired value.


Faster then your version:
SELECT id FROM table_name ORDER BY id DESC   LIMIT 1

The 'elegant' solution:
SELECT currval('tablename_sequence_id');



[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux