X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 945AD52A3D for ; Thu, 30 Jun 2005 10:50:36 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32952-08 for ; Thu, 30 Jun 2005 13:50:33 +0000 (GMT) Received: from s001.mxhosting.nl (unknown [213.206.92.11]) by svr1.postgresql.org (Postfix) with ESMTP id 5DDE852A15 for ; Thu, 30 Jun 2005 10:50:31 -0300 (ADT) Received: from pinbizz.xs4all.nl ([82.92.94.47] helo=[192.168.11.224]) by s001.mxhosting.nl with asmtp (Exim 4.40 (FreeBSD)) id 1Dnyrp-000LHf-ML for pgsql-sql@postgresql.org; Thu, 30 Jun 2005 15:14:09 +0200 Message-ID: <42C3F8A1.5000905@dltmedia.nl> Date: Thu, 30 Jun 2005 15:50:25 +0200 From: "M.D.G. Lange" User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Updatable view Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - s001.mxhosting.nl X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [26 6] X-AntiAbuse: Sender Address Domain - dltmedia.nl X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.021 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/377 X-Sequence-Number: 21978 I have been looking around to get an idea how to make RULES on a VIEW for INSERT , UPDATE and DELETE of a VIEW with an INNER JOIN. First the idea: There are 3 tables, those are related one way or another, combined in this view: pg_user (ok, it's a view really) tblcontacts (with contact information like first name and lastname and such) tbldepartments (a user works at a certain department) tblusersettings (some extra information about the user which is not in pg_shadow, eg locked status, birthdate and such) tblusersettings has the links to tbldepartments, tblcontacts and pg_user (via a trigger to check if the user exists) --- CREATE OR REPLACE VIEW usersview AS SELECT tblusersettings.userid, tblusersettings.birthdate, tblusersettings.islocked, pg_user.usename, pg_user.usesuper, pg_user.valuntil, tbldepartments.departmentname, tbldepartments."ID" AS departmentid, tbldepartments.dateformatid, tbldepartments.currencyid, tblcontacts."ID" AS contactid, tblcontacts.firstname, tblcontacts.lastname, tblcontacts.gender, tblcontacts."function", tblcontacts.phone, tblcontacts.email, tblcontacts.languageid FROM tblusersettings JOIN pg_user ON tblusersettings.userid = pg_user.usesysid JOIN tbldepartments ON tblusersettings.departmentid = tbldepartments."ID" JOIN tblcontacts ON tblusersettings.contactid = tblcontacts."ID" ORDER BY pg_user.usename; the view is OK, so I want something like this to INSERT a user: CREATE OR REPLACE RULE insertuser AS ON INSERT TO usersview DO INSTEAD ( (CREATE USER NEW.usename); (INSERT INTO tblcontacts(firstname, lastname, gender, titleid, function, phone, email, languageid, attentionid) VALUES (NEW.firstname, NEW.lastname, NEW.gender, 0, NEW.function, NEW.phone, NEW.email, NEW.mobile, NEW.languageid, 0)); ); The idea is: - Create a user - Create a contact - Create usersettings for the user with in it the newly created contactid and userid. How impossible is this? How do I get the newly created contact and user id's in the usersettings table? TIA, Michiel