From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | Max Rudensky <fonin(at)ziet(dot)zhitomir(dot)ua> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: OIDs in triggers |
Date: | 2001-02-23 16:50:59 |
Message-ID: | Pine.BSF.4.21.0102230844540.17275-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sat, 17 Feb 2001, Max Rudensky wrote:
> Hi folks,
>
> Here's what I have:
>
> create table contact (
> contact_id serial,
> ... <skipped fields>
> primary key (contact_id)
> );
>
> create table customers (
> customer_id serial,
> shipping_contact_id int4,
> billing_contact_id int4,
> ... <skipped fields>
>
> primary key (customer_id)
> );
>
> Well, I want to write a trigger on CUSTOMERS that will insert 2 records into table CONTACT and
> link it to fields shipping_contact_id and billing_contact_id in CUSTOMERS. But how, if I won't know
> oids of inserted rows ? I may remember sequence's nextval in variable and use it in both insert and update
> statements, but during many insert in contact table sequence's nextval may be used by
> concurrent transactions, so one of them will be rolled back.
>
> I prefer to do it with PL/pgSQL, anyway I can't use C.
You shouldn't ever have two transactions getting the same value from
nextval on the sequence. It should be guaranteed to be unique, so getting
the currval after each insert or nextval before should work.
Note that serial does not guarantee that the number sequence you get will
not have holes just that they are unique.
From | Date | Subject | |
---|---|---|---|
Next Message | Renaud Tthonnart | 2001-02-23 17:02:30 | Updating an array |
Previous Message | ochapiteau | 2001-02-23 16:48:22 | drop a constraint |