Help with Update Rule on View - 2nd Attempt - Mailing list pgsql-novice

From Lenorovitz, Joel
Subject Help with Update Rule on View - 2nd Attempt
Date
Msg-id 7119BB016BDF6445B20A4B9F14F50B2D44A8CE@WILSON.usap.gov
Whole thread Raw
List pgsql-novice
I tried to post this the other day, but didn't get any responses and
never saw it show up in the digest.  Here it is again if anyone can
offer any insight:


I'm trying to create a schema in which there will be simple a view for
each table that will have the same columns and can be acted on in the
same way as the underlying table

An example of one table and its view would be:

CREATE TABLE test (id int, text_field varchar(100)); CREATE VIEW _test
AS SELECT * FROM test;

I'd like to be able to create both the views and the insert, update,
delete rules for the views in an automated fashion via a script that
uses the information schema to get all of the table names.  All is fine
and good with the insert and delete rules and no problem to
automatically generate this:

CREATE RULE _test_oi_rule AS ON INSERT TO _test DO INSTEAD INSERT INTO
test VALUES (NEW.*); CREATE RULE _test_od_rule AS ON DELETE TO _test DO
INSTEAD DELETE FROM test WHERE id = OLD.id;

However, I'm not sure how to create the update rule without having to go
through the gory task of specifying each column by name.  Yes, I could
also use the information schema to automate this as well, but it just
seems ugly.  Is there any way to create an update rule that's something
like this:

CREATE RULE _test_ou_rule AS ON UPDATE TO _test SET test.* = NEW.*;
-- or even better a command that will only update changed columns (i.e.,
WHERE NEW.* <> OLD.*)

I imagine I could instead delete the old record and insert the new one,
but that doesn't seem right either and seems like could be perilous.
Maybe I'm overlooking something obvious, but any help to find a nice
clean solution would be appreciated.

Thanks,
JL

pgsql-novice by date:

Previous
From: "Daniel T. Staal"
Date:
Subject: Re: Sort question ! ! !
Next
From: "K. Kelly Close"
Date:
Subject: Re: PostgreSQL back end to Excel ap