Better to use a Sequence?

From: Alan Gutierrez <ajglist_at_izzy.net>
Date: Tue, 07 Jan 2003 21:52:37 GMT
Message-ID: <F_HS9.5943$t06.83848_at_news2.east.cox.net>



Given this hackeneyed example:

create table customer_order (order_id integer, primary key (order_id)); create table customer_order_item (

   order_id integer, order_item_id integer,    primary key (order_id, order_item_id),    foreign key (order_id) references (order) );

insert into customer_order_item (order_id, order_item_id) select 1, max (coalesce(order_item_id, 0)) + 1

   from customer_order_item
  where order_id = 1;

I found that in a transaction a data race will cause the looser of the race to abort and rollback.

Now I am thinking sequence or order_item_id, but that doesn't *feel* right.

Alan Gutierrez Received on Tue Jan 07 2003 - 22:52:37 CET

Original text of this message