From: | Ericson Smith <eric(at)did-it(dot)com> |
---|---|
To: | Erik Price <eprice(at)ptc(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: LAST_INSERT_ID equivalent |
Date: | 2003-06-12 19:26:55 |
Message-ID: | 3EE8D3FF.7050506@did-it.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
No, it would only get the *next* value. Only one increment is performed.
Regards
- Ericson
Erik Price wrote:
>
>
> Ericson Smith wrote:
>
>> While many others use currval(), we tend to grab the next ID provided
>> by nextval('seq') and use that to be inserted with the record. The
>> process is very atomic, and the ID is available to be used by the
>> rest of your program. The only drawback is if your insert query fails
>> there will be a hole in the sequence.
>
>
> So you're saying that you perform a pre-query to fetch the nextval,
> then you include that in your query where you perform the INSERT? I
> see. Since this is all part of the same transaction, the nextval value
> won't overwrite another simultaneous INSERT, I assume. This seems
> like a good way to do it too. I don't mind the holes in the sequence,
> but wouldn't this INSERT cause the sequence to increment the primary
> key yet again?
>
>
>
> Erik
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
From | Date | Subject | |
---|---|---|---|
Next Message | sector119 | 2003-06-12 19:27:58 | sector119@mail.ru |
Previous Message | Bruno Wolff III | 2003-06-12 19:26:53 | Re: LAST_INSERT_ID equivalent |