Skip site navigation (1) Skip section navigation (2)

Get last serial (autoincrement) value

From: Andrei Verovski (aka MacGuru) <andreil1(at)mail(dot)starlett(dot)lv>
To: pgsql-php(at)postgresql(dot)org
Subject: Get last serial (autoincrement) value
Date: 2003-09-01 10:34:32
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-php

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.

May be there is more elegant way? I am using ADODB. ADODB has function 
which in theory allows to obtain
last inserted serial (autoincrement) id, but for Postgres it return OID.

This is from ADODB manual:

Insert_ID( )
Returns the last autonumbering ID inserted. Returns false if function 
not supported.
Only supported by databases that support auto-increment or object id's, 
such as PostgreSQL, MySQL and MSSQL currently. PostgreSQL returns the 
OID, which can change on a database reload.

Thanks in advance for any suggestion.

*   Best Regards   ---   Andrei Verovski
*   Personal Home Page
*   Mac, Linux, DTP, Development, IT WEB Site


pgsql-php by date

Next:From: David BusbyDate: 2003-09-01 18:11:06
Subject: Re: Get last serial (autoincrement) value
Previous:From: scott.marloweDate: 2003-08-28 16:13:28
Subject: Re: write to next-Page on PHP with Pdflib

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group