X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 9D2479FB2B7 for ; Tue, 11 Jul 2006 08:25:27 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 28470-09 for ; Tue, 11 Jul 2006 08:25:16 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id 3A2A59FB27E for ; Tue, 11 Jul 2006 08:25:15 -0300 (ADT) Received: from root by ciao.gmane.org with local (Exim 4.43) id 1G0GMQ-0001HI-Dw for pgsql-sql@postgresql.org; Tue, 11 Jul 2006 13:25:02 +0200 Received: from anthonychavez.org ([166.70.126.66]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 11 Jul 2006 13:25:02 +0200 Received: from acc by anthonychavez.org with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 11 Jul 2006 13:25:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Anthony Chavez Subject: ON INSERT view rule Date: Tue, 11 Jul 2006 04:53:40 -0600 Lines: 76 Message-ID: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: anthonychavez.org User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Cancel-Lock: sha1:tlvlVEpKrTnpBrNOA9KaUJPcy4U= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/172 X-Sequence-Number: 25746 --=-=-= Content-Transfer-Encoding: quoted-printable Hello, pgsql-sql! What I've got here are a couple of ON INSERT rules for a view. The second rule is what I'm concerned about. I wrote it with PostgreSQL's ACID compliance in mind, but can I trust it? From=20what I gather, if I were to simply use NEW.address_line_id rather than address_lines_id_seq.last_value, it would be replaced by nextval(address_line_id_seq), so I'm trying to work around that. If there is there a better way to do this, I'm all ears. Would lastval() work for me in this case? Thanks! =2D-=20 Anthony Chavez http://anthonychavez.org/ mailto:acc@anthonychavez.org jabber:acc@jabber.anthonychavez.org CREATE OR REPLACE VIEW addresses_address_lines AS SELECT a.id AS address_id, al.id AS address_line_id, line, ordering FROM addresses a INNER JOIN address_lines al ON al.address_id =3D a.id LEFT OUTER JOIN junctions ON parent_table =3D 'address_lines' AND parent_id =3D al.id AND child_table =3D 'display_orderings' LEFT OUTER JOIN display_orderings o ON o.id =3D child_id; CREATE OR REPLACE RULE insert_address_lines AS ON INSERT TO addresses_address_lines DO INSTEAD INSERT INTO address_lines (address_id, line) VALUES (NEW.address_id, NEW.line); CREATE OR REPLACE RULE insert_display_orderings AS ON INSERT TO addresses_address_lines DO UPDATE display_orderings SET ordering =3D NEW.ordering FROM address_lines_id_seq INNER JOIN junctions ON parent_table =3D 'address_lines' AND parent_id =3D last_value AND child_table =3D 'display_orderings' WHERE ordering <> NEW.ordering AND display_orderings.id =3D child_id; --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.4 (Darwin) iQEVAwUBRLODWPAIdTFWAbdTAQLHYQf+Kmb1ZLFSZaf05ITZJMOqMHBgpOCVYq6Q Bu8+kK8d1ilN0BPeDqVrlH16kmv5EveZmyqpcM4Q8tBO8HK7hZqEwkkrTHJL1Sng 1qrVCQteS8EkQSpu24aHY72lFLzBullrmB59fZNFwstSjdjHo6as/b+NuqXnaboS 9HJjMQrqBV7igRHWLs07x1vPXuZ3gJXdV2kFbFR8rlSCyGYvmITrJGIcin868wqL aCUVjgXRNvdGQlPwv+SwZZmbnNp4hrQMf2AYsSAtUQusVfzz8V+doYTBtWCM9V6h DdGkDbTIjXS92f4iWj2b4v9rcLBRfJJtydvleqi6Lgw/ed7Eo2zCUQ== =OP6p -----END PGP SIGNATURE----- --=-=-=--