Re: get a pkey/id back from/after an insert

From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: Bruno Wolff III <bruno(at)wolff(dot)to>, Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
Cc: Corey <corey(at)bitworthy(dot)net>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: get a pkey/id back from/after an insert
Date: 2006-06-20 17:09:21
Message-ID: C0BDA401.D188%sdavis2@mail.nih.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 6/20/06 12:34 PM, "Bruno Wolff III" <bruno(at)wolff(dot)to> wrote:

> On Mon, Jun 19, 2006 at 19:10:01 -0700,
> Richard Broersma Jr <rabroersma(at)yahoo(dot)com> wrote:
>> Well for testing purposes it should be fine to explicitly call out
>> currentval. But be careful if
>> you are going to be using multiply connections at onces. I am not sure that
>> currentval will give
>> you what you want if another connection calls nextval first before you insert
>> a record to your
>> child table.
>
> It will do what is expected. currval returns the last value allocated in
> your session. It wouldn't be much use if other connections could change
> the value out from under you.

While this may be obvious, if you are coming from other database systems, it
may come as a surprise that under the postgres system, you do not
necessarily get a "gapless" id. There may be gaps (1,2,3,7,8,9). Once a
value is allocated, it is not reused. This isn't at all important, but as I
said, it may surprise some.

Sean

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Richard Broersma Jr 2006-06-20 17:30:31 Re: replace
Previous Message Luis Silva 2006-06-20 16:41:33 replace