Re: [Q] Sequences, last_value and inserts

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: "Roderick A(dot) Anderson" <raanders(at)acm(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [Q] Sequences, last_value and inserts
Date: 2002-11-01 20:02:43
Message-ID: 20021101200243.GB1266@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Nov 01, 2002 at 11:50:30 -0800,
"Roderick A. Anderson" <raanders(at)acm(dot)org> wrote:
>
> I'm inserting some values into a table with a serial field. This is being
> done using Perl and the DBI. I then pull back using 'last_value' what I
> hope is the value for the insert. The thought came to mind that if the
> database is getting hit pretty hard there may be another access of the
> sequence and last_value will be wrong 'for me'.
> Question is how do I insure I get the correct last-value? Enclose in a
> BEGIN/END block? (How's that done using Perl? - my DBI book isn't at
> hand).

You want to use currval. This can be used within a single session safely.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-11-01 20:18:59 Re: Update FROM clause?
Previous Message Bruno Wolff III 2002-11-01 19:56:32 Re: FIFO Queue Problems