From: | Michal Paluchowski <mpaluchowski(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Multiple operations on single rule, revisited |
Date: | 2007-08-10 08:37:16 |
Message-ID: | 8110440087.20070810103716@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
the following is a rework of what I wanted to achieve when posting
yesterday. Since that post didn't seem to attract attention, I tried
to do what I wanted to do differently.
Now, creating a RULE for a view allows defining several operations for
it. I was happy to discover that actually and quickly rewrote my rule
to look this way:
CREATE OR REPLACE RULE "_UPDATE_not_existing" AS
ON UPDATE TO trade_material_view
WHERE NOT material_exists(new.diameter, new.material_length, new.weight, new.loss, new.bar_type_id, new.metal_type_id)
DO (
INSERT INTO material (id, diameter, material_length, weight, loss, bar_type_id, metal_type_id)
VALUES (nextval('material_id_seq'::regclass), new.diameter, new.material_length, new.weight, new.loss, new.bar_type_id, new.metal_type_id);
INSERT INTO trade_material (material_id)
VALUES (currval('material_id_seq'::regclass)
);
);
material_exists is my own, boolean-returning, custom function. Works
by checking whether a given material (with given characteristics)
exists in the appropriate table.
The problem is, PostgreSQL just performs the first INSERT and happily
ignores the rest. As much as I hate swearing, I shouted one large WFT
on this one...
Can someone PLEASE explain to me what's happening? First insert works
like a charm, second one is non-existent to Postgres. I can replace
the second INSERT with any other command, including one deleting
everything in say 'trade_material' and it doesn't work anyway.
--
Best regards,
Michal mailto:mpaluchowski(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Jonas Gauffin | 2007-08-10 08:45:10 | Re: Allowing LAN connections |
Previous Message | Louis-David Mitterrand | 2007-08-10 08:11:29 | Re: timestamp skew during 7.4 -> 8.2 upgrade |