From: | "Dean Gibson (DB Administrator)" <postgresql(at)ultimeth(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Creating a RULE for UPDATing a VIEW |
Date: | 2009-05-03 16:50:41 |
Message-ID: | 49FDCB61.6020206@ultimeth.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Using PostgreSQL version 8.3.0:
For various reasons, I have a number of VIEWs that are (except for the
schema/table/view names) automatically generated as identity mappings of
corresponding TABLEs; eg:
CREATE VIEW public.yyy AS SELECT * FROM private.zzz;
Since we don't have updatable VIEWS yet, I tried:
CREATE RULE _update AS ON UPDATE TO public.yyy DO INSTEAD
UPDATE private.zzz SET (*) = NEW.* WHERE key_field = OLD.key_field;
In order to make the automatic generation easy, I'm trying to make the
syntax as general as possible, in particular, so that I don't have to
list all of the column names (that appears to work). However, the above
(and other ingenious, but also incorrect, syntaxes) produces an error
message. So, I tried:
CREATE RULE _update AS ON UPDATE TO public.yyy DO INSTEAD
(DELETE FROM private.zzz WHERE key_field = OLD.key_field;
INSERT INTO private.zzz VALUES( NEW.*) );
This is syntactically accepted, but when I attempt to UPDATE a row, the
old row is deleted but the new row is not inserted. Manually listing
the NEW.columns in place of "NEW.*" doesn't help.
-- Dean
--
Mail to my list address MUST be sent via the mailing list.
All other mail to my list address will bounce.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-05-03 17:36:42 | Re: Creating a RULE for UPDATing a VIEW |
Previous Message | Isaac Dover | 2009-05-03 03:47:50 | Re: Comparing two tables of different database |