X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BCA839DC815 for ; Wed, 28 Dec 2005 11:35:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91415-01 for ; Wed, 28 Dec 2005 11:35:06 -0400 (AST) X-Greylist: delayed 00:06:39.906999 by SQLgrey- Received: from web26001.mail.ukl.yahoo.com (web26001.mail.ukl.yahoo.com [217.12.10.212]) by postgresql.org (Postfix) with SMTP id EFEB69DC827 for ; Wed, 28 Dec 2005 11:34:58 -0400 (AST) Received: (qmail 2473 invoked by uid 60001); 28 Dec 2005 15:28:23 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.de; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=f271Bt5/xzt07ymG733UcFqJ63poX7apebFMg4n4b0cMvyXO8Mj2Xzq4lBFJwfGkf9xNA64ra52FvtRcpEiJ21037UVxWGxxzwDDIll1xiCr/IPrqlzTof2VOq1cjia5FhGOEsmtykG57/IeKMXqwSI2wQnO0xo03wcUg2QXUOg= ; Message-ID: <20051228152823.2471.qmail@web26001.mail.ukl.yahoo.com> Received: from [84.142.37.66] by web26001.mail.ukl.yahoo.com via HTTP; Wed, 28 Dec 2005 16:28:23 CET Date: Wed, 28 Dec 2005 16:28:23 +0100 (CET) From: J Crypter Subject: instead of trigger in pg To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.479 required=5 tests=[DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.479 X-Spam-Level: X-Archive-Number: 200512/218 X-Sequence-Number: 23760 Hi, I would like to implement a 1:n relation between two tables. An auto-generated number should be used as primary key which connects both tables. Example: table 1: name | number (prim_key) table 2: country | number_table1 (foreign key) View: number_table1 | name | country I would like to insert into both tables in one step. "Insert into view (name, country)values('name','country');" Oracle supports an instead-of-trigger but Postgres doesn't do this. CREATE or replace FUNCTION insertInto() RETURNS trigger AS ' BEGIN insert into table1(name)values(NEW.name); insert into table2(number,country)values(NEW.number,NEW.country); RETURN NEW; END; ' LANGUAGE plpgsql; CREATE TRIGGER insert_TR BEFORE INSERT OR UPDATE ON view FOR EACH ROW EXECUTE PROCEDURE insertInto(); I would like to implement something like this but I don't know how to do. Thank you for you help! Jakob ___________________________________________________________ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de