Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 9DCB7632DA9 for ; Sun, 3 May 2009 14:16:57 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 72172-04 for ; Sun, 3 May 2009 14:16:56 -0300 (ADT) X-Greylist: delayed 00:26:28.519712 by SQLgrey-1.7.6 Received: from mail.mailpen.net (mail.mailpen.net [204.13.164.167]) by mail.postgresql.org (Postfix) with ESMTP id 39DB7632CE4 for ; Sun, 3 May 2009 14:16:56 -0300 (ADT) Received: from [172.24.2.1] (pool-71-121-132-181.sttlwa.dsl-w.verizon.net [71.121.132.181]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.mailpen.net (Postfix) with ESMTP id 5C310670722 for ; Sun, 3 May 2009 09:50:25 -0700 (PDT) Message-ID: <49FDCB61.6020206@ultimeth.com> Date: Sun, 03 May 2009 09:50:41 -0700 From: "Dean Gibson (DB Administrator)" Organization: UltiMeth Systems User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Creating a RULE for UPDATing a VIEW Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200905/10 X-Sequence-Number: 32502 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.