Re: Get last serial (autoincrement) value

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Andrei Verovski <andreil1(at)mail(dot)starlett(dot)lv>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: Get last serial (autoincrement) value
Date: 2003-09-01 19:01:22
Message-ID: 20030901190122.GA1782@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

On Mon, Sep 01, 2003 at 13:34:32 +0300,
Andrei Verovski <andreil1(at)mail(dot)starlett(dot)lv> 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.

How you want to do this, depends on what you what to do with the number.

Normally if you just inserted a record that would create a new id and you
want to use that id to enter in another table, then you want to call
currval.

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Chris FR 2003-09-02 14:50:15 Strange browser behavior when querying PostgreSql database
Previous Message Frank Bax 2003-09-01 18:48:30 Re: Get last serial (autoincrement) value