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: Pine.BSO.4.64.0710181506040.30980@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Josh Berkus 2007-10-18 19:57:37 Re: Fw: postgresql experts please help
Previous Message Andrei Ilitchev 2007-10-18 18:47:05 Re: Fw: postgresql experts please help