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 9C6A99DC80F for ; Wed, 28 Dec 2005 12:03:35 -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 93527-07 for ; Wed, 28 Dec 2005 12:03:33 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.194]) by postgresql.org (Postfix) with ESMTP id 165639DC827 for ; Wed, 28 Dec 2005 12:03:32 -0400 (AST) Received: by wproxy.gmail.com with SMTP id i27so569103wra for ; Wed, 28 Dec 2005 08:03:32 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=g9kLi7F4RXpDO4/MQDGXB+zyiO28XX3B287Z2EiVKRNbmpy3qTLC94rh/1bFYf/cEXQk4fcJl74etQXloodwdLF4XyGDyuatcVPBQnJO5+lTiA4M/GuJaRb0iKxAwSCXVLNJiiQ1qyFUMOxP5s4S4YhfIH3rMhnyDtzQopCr+zM= Received: by 10.54.113.6 with SMTP id l6mr8607745wrc; Wed, 28 Dec 2005 08:03:32 -0800 (PST) Received: by 10.54.92.14 with HTTP; Wed, 28 Dec 2005 08:03:32 -0800 (PST) Message-ID: Date: Wed, 28 Dec 2005 11:03:32 -0500 From: Jaime Casanova To: J Crypter Subject: Re: instead of trigger in pg Cc: pgsql-sql@postgresql.org In-Reply-To: <20051228152823.2471.qmail@web26001.mail.ukl.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <20051228152823.2471.qmail@web26001.mail.ukl.yahoo.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200512/221 X-Sequence-Number: 23763 On 12/28/05, J Crypter wrote: > 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. > postgres uses rules for this situation... and yes there are INSTEAD OF rule= s... > 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 > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > -- Atentamente, Jaime Casanova (DBA: DataBase Aniquilator ;)