Re: Update view/table rule order of operations or race condition - Mailing list pgsql-general

From Dan Fitzpatrick
Subject Re: Update view/table rule order of operations or race condition
Date
Msg-id D35E88A5-1991-49C0-9B1E-B2AF294F01A7@eparklabs.com
Whole thread Raw
In response to Update view/table rule order of operations or race condition  (Dan Fitzpatrick <dan@eparklabs.com>)
Responses Re: Update view/table rule order of operations or race condition  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
I think I found the problem with this. The rule:

CREATE OR REPLACE RULE insert_options AS
  ON INSERT TO options DO INSTEAD
    (INSERT INTO a (a_id, type_id, name)
       VALUES (new.options_id, 6, new.options_name);
     UPDATE a_item SET val = new.quantity
       WHERE a_item.a_id = new.options_id AND a_item.type_id = 1;
     UPDATE a_item SET val = new.price
       WHERE a_item.a_id = new.options_id AND a_item.type_id = 2;
     UPDATE a_item SET val = new.discount
       WHERE a_item.a_id = new.options_id AND a_item.type_id = 3;
);


Is creating a new value from the sequence a_a_id_seq for
"new.options_id" on each UPDATE call. How do I use the variable
new.options_id in the three update statements without incrementing the
sequence again?







pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: \copy command: how to define a tab character as the delimiter
Next
From: Tom Lane
Date:
Subject: Re: question on 8.4.2 build postgres C functions