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

Re: MySQL LAST_INSERT_ID() to Postgres

From: Joshua Drake <jd(at)commandprompt(dot)com>
To: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
Cc: Bill <pg(at)dbginc(dot)com>, "Steve Atkins" <steve(at)blighty(dot)com>, "pgsql-general General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: MySQL LAST_INSERT_ID() to Postgres
Date: 2008-08-28 22:18:15
Message-ID: 20080828151815.59ef670c@jd-laptop (view raw, whole thread or download thread mbox)
Lists: pgsql-general
On Thu, 28 Aug 2008 16:06:14 -0600
"Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> wrote:

> On Thu, Aug 28, 2008 at 3:38 PM, Bill <pg(at)dbginc(dot)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: 
PostgreSQL Community Conference:
United States PostgreSQL Association:
Donate to the PostgreSQL Project:

In response to


pgsql-general by date

Next:From: Matthew DennisDate: 2008-08-28 22:21:59
Subject: Re: indexes on functions and create or replace function
Previous:From: Albretch MuellerDate: 2008-08-28 22:14:01
Subject: Re: ERROR: relation . . . does not exist

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