Re: Get last serial (autoincrement) value

From: Frank Bax <fbax(at)sympatico(dot)ca>
To: pgsql-php(at)postgresql(dot)org
Subject: Re: Get last serial (autoincrement) value
Date: 2003-09-01 18:48:30
Message-ID: 5.2.1.1.0.20030901144559.00a0c3e0@pop6.sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

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');

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Bruno Wolff III 2003-09-01 19:01:22 Re: Get last serial (autoincrement) value
Previous Message David Busby 2003-09-01 18:11:06 Re: Get last serial (autoincrement) value