Re: Update view/table rule order of operations or race condition

From: Dan Fitzpatrick <dan(at)eparklabs(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Update view/table rule order of operations or race condition
Date: 2010-03-09 17:42:26
Message-ID: D35E88A5-1991-49C0-9B1E-B2AF294F01A7@eparklabs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-03-09 17:56:26 Re: question on 8.4.2 build postgres C functions
Previous Message Raymond O'Donnell 2010-03-09 17:39:15 Re: \copy command: how to define a tab character as the delimiter