X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4E434475AE4 for ; Thu, 24 Apr 2003 15:05:25 -0400 (EDT) Received: from jal.clueinc.net (xd84b436b.ip.e-nt.net [216.75.67.107]) by postgresql.org (Postfix) with ESMTP id 54C8B474E42 for ; Thu, 24 Apr 2003 15:05:17 -0400 (EDT) Received: from jal.clueinc.net (localhost [127.0.0.1]) by jal.clueinc.net (8.12.9/8.12.9/Debian-3) with ESMTP id h3OJ5ErE006907 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Thu, 24 Apr 2003 14:05:14 -0500 Received: (from jal@localhost) by jal.clueinc.net (8.12.9/8.12.9/Debian-3) id h3OJ5DHc006905 for pgsql-sql@postgresql.org; Thu, 24 Apr 2003 14:05:13 -0500 Date: Thu, 24 Apr 2003 14:05:13 -0500 From: Jamie Lawrence To: pgsql-sql@postgresql.org Subject: Rule definition problem Message-ID: <20030424190513.GW15321@jal.clueinc.net> Mail-Followup-To: pgsql-sql@postgresql.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.4i X-Spam-Status: No, hits=-12.1 required=5.0 tests=BAYES_10,USER_AGENT_MUTT autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/380 X-Sequence-Number: 13081 Hi all - I'm trying to define rules for inserts and updates on a view. My problem is that I'm unsure on how to get the value of a field on one table and use it in an insert into another. The tables in question have a one-one relationship (A little warped, I know; the 'inventory' table has data common to all items, and the 'music' table has data specific to, well, inventory items of type 'music'.) The underlying tables and the view look something like this: create table inventory ( id serial unique not null, manufacturer_num text unique, category_id int not null, [...] ); create table music ( id serial unique not null, inventory_id int not null, year int, label text, [...] CONSTRAINT category_exists foreign key (inventory_id) references inventory (id) on delete cascade ); create view music_view as select inventory.id, inventory.manufacturer_num, inventory.category_id, [...], music.year, music.label, [...] from inventory, music where inventory.id = music.inventory_id; For an Insert rule, I need to get the value of inventory.id we just inserted and stash it in music.inventory_id. Is this possible in a rule, or do I need to do with in a trigger? Am I on crack? TIA. -j -- Jamie Lawrence jal@jal.org "Perl is Internet Yiddish." - Yoz Graehme