Re: Fw: postgresql experts please help - Mailing list pgsql-jdbc

From Kris Jurka
Subject Re: Fw: postgresql experts please help
Date
Msg-id Pine.BSO.4.64.0710181506040.30980@leary.csoft.net
Whole thread Raw
In response to Re: Fw: postgresql experts please help  ("Andrei Ilitchev" <andrei.ilitchev@oracle.com>)
Responses Re: Fw: postgresql experts please help  (Josh Berkus <josh@agliodbs.com>)
List 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

pgsql-jdbc by date:

Previous
From: "Andrei Ilitchev"
Date:
Subject: Re: Fw: postgresql experts please help
Next
From: Josh Berkus
Date:
Subject: Re: Fw: postgresql experts please help