From: Frank Bax <fbax@sympatico.ca>
To: pgsql-php@postgresql.org
Subject: Re: Get last serial (autoincrement) value
Date: Mon, 01 Sep 2003 14:48:30 -0400
Message-ID: <5.2.1.1.0.20030901144559.00a0c3e0@pop6.sympatico.ca> (raw)
In-Reply-To: <DF9C8135-DC67-11D7-B235-000A959C9730@starlett.lv>
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');
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: fbax@sympatico.ca
Subject: Re: Get last serial (autoincrement) value
In-Reply-To: <5.2.1.1.0.20030901144559.00a0c3e0@pop6.sympatico.ca>
References: <DF9C8135-DC67-11D7-B235-000A959C9730@starlett.lv> <5.2.1.1.0.20030901144559.00a0c3e0@pop6.sympatico.ca>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox