Re: MySQL LAST_INSERT_ID() to Postgres - Mailing list pgsql-general

From Joshua Drake
Subject Re: MySQL LAST_INSERT_ID() to Postgres
Date
Msg-id 20080828151815.59ef670c@jd-laptop
Whole thread Raw
In response to Re: MySQL LAST_INSERT_ID() to Postgres  ("Scott Marlowe" <scott.marlowe@gmail.com>)
Responses Re: MySQL LAST_INSERT_ID() to Postgres
List pgsql-general
On Thu, 28 Aug 2008 16:06:14 -0600
"Scott Marlowe" <scott.marlowe@gmail.com> wrote:

> On Thu, Aug 28, 2008 at 3:38 PM, Bill <pg@dbginc.com> wrote:
> > I am new to PostgreSQL but it seems to me that lastval() will only
> > work if the insert does not produce side effects that call
> > nextval(). Consider the case where a row is inserted into a table
> > that has an after insert trigger and the after insert trigger
> > inserts a row into another table which has a serial primary key. In
> > that case I assume that lastval() will  return the value from the
> > serial column in the second table.
>
> No, setval, currval, and lastval all require as an argument a sequence
> name.  So the real issue is you have to know the sequence name to use
> them.

lastval() does not take a sequence name.

Joshua D. Drake



--
The PostgreSQL Company since 1997: http://www.commandprompt.com/
PostgreSQL Community Conference: http://www.postgresqlconference.org/
United States PostgreSQL Association: http://www.postgresql.us/
Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate



pgsql-general by date:

Previous
From: "Albretch Mueller"
Date:
Subject: Re: ERROR: relation . . . does not exist
Next
From: Alvaro Herrera
Date:
Subject: Re: MySQL LAST_INSERT_ID() to Postgres