Re: Sequence - Mailing list pgsql-jdbc

From Dave Cramer
Subject Re: Sequence
Date
Msg-id 1042352782.2327.16.camel@inspiron.cramers
Whole thread Raw
In response to Sequence  (Alan Roberto Romaniuc <romaniuc@klais.com.br>)
List pgsql-jdbc
Ross,

Damn, you're right. Still I prefer to get the id first, but ya, I
shoulda checked.

Thanks for catching that.

Dave

On Sun, 2003-01-12 at 00:07, Ross J. Reedstrom wrote:
> On Sat, Jan 11, 2003 at 08:41:31PM -0500, Dave Cramer wrote:
> > Alan, Simon,
> >
> > You can't do this, at least not safely.
> >
> > Sequences can't be rolled back and are visible across transactions. In
> > other words if thread 1 inserted a row, and before you read the sequence
> > thread b inserted a row, you would get the same value for both threads.
> > The only way I know is to get the sequence before hand and insert it.
> > The overhead is the same.
>
> Dave -
> You really should test these things before stating with such assurance
> what will happen. Yes, sequences are outside transactions, but they
> _do_ honor connections. So, if  your two hypothetical threads are
> using seperate connections (which they _must_ do, BTW), each can use
> the currval(seqname) to retrieve the value used in that connection,
> regardless of what happens in the other.
>
> Ross
--
Dave Cramer <Dave@micro-automation.net>


pgsql-jdbc by date:

Previous
From: Simon Mitchell
Date:
Subject: Re: Sequence
Next
From: Dave Cramer
Date:
Subject: Re: Sequence