Getting the next sequence value safely - Mailing list pgsql-jdbc

From Jeremy Buchmann
Subject Getting the next sequence value safely
Date
Msg-id F2FC22BB-7A5C-11D6-BD7D-000502E740BA@wellsgaming.com
Whole thread Raw
Responses Re: Getting the next sequence value safely  (Dave Cramer <Dave@micro-automation.net>)
List pgsql-jdbc
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


pgsql-jdbc by date:

Previous
From: Robinson
Date:
Subject: Re: RE : Java GUI development
Next
From: Bruce Momjian
Date:
Subject: Re: [PATCHES] JDBC CStmt (inline this time)