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

Re: Fw: postgresql experts please help

From: Kris Jurka <books(at)ejurka(dot)com>
To: Andrei Ilitchev <andrei(dot)ilitchev(at)oracle(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org, Marina Vatkina <Marina(dot)Vatkina(at)Sun(dot)COM>
Subject: Re: Fw: postgresql experts please help
Date: 2007-10-18 19:09:39
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc

On Thu, 18 Oct 2007, Andrei Ilitchev wrote:

> In the docs I discovered "select lastval()" which seems to behave exactly 
> like @@Identity in Sybase returning the latest nextval that was obtained in 
> the current session by no-matter-which sequence.
> That's exactly the functionality I need - much easier to use because no need 
> to track the name.
> Can you think of any reason why using "select lastval()" would be a bad idea?

If you have an after trigger on the table that you're inserting into and 
it inserts into another table with a serial column, the lastval call will 
use the wrong sequence.  Now this is also a problem with currval if you 
have a trigger that inserts into the same table, but that's an unlikely 
application design.  Inserting into another table is something that you'll 
find with systems that do auditing or sometimes horizontal partitioning of 
a table.

Kris Jurka

In response to


pgsql-jdbc by date

Next:From: Josh BerkusDate: 2007-10-18 19:57:37
Subject: Re: Fw: postgresql experts please help
Previous:From: Andrei IlitchevDate: 2007-10-18 18:47:05
Subject: Re: Fw: postgresql experts please help

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