Re: Getting the next sequence value safely

From: Dave Cramer <Dave(at)micro-automation(dot)net>
To: Jeremy Buchmann <jeremy(at)wellsgaming(dot)com>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Getting the next sequence value safely
Date: 2002-06-08 05:18:29
Message-ID: 1023513510.1644.788.camel@inspiron.cramers
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Jeremy,

No just do a select nextval('sequencename') and then insert it with the
result.

Dave
On Fri, 2002-06-07 at 17:24, Jeremy Buchmann wrote:
> Hi,
>
> I have a situation where I want to insert a record into a table
> which will give the record a unique id via a sequence. Is there
> an easy and safe way to get this id number either right before
> or right after the insertion? My best idea is to select last_value
> from the sequence and then assume that the record will get
> last_value + 1 when it is inserted (the insertion would happen
> right after the select). Is this a safe assumption?
> What happens if I wrap these operations in a transaction? Is
> there a standard way of doing this?
>
> Thanks,
> --Jeremy
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message tony 2002-06-08 07:19:44 Re: RE : Java GUI development
Previous Message Bruce Momjian 2002-06-08 02:18:10 Re: [PATCHES] JDBC CStmt (inline this time)