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 8C35F11F6093 for ; Tue, 18 Apr 2006 15:30:39 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0.248 X-Spam-Level: X-Spam-Status: No, score=0.248 required=5 tests=[AWL=0.248] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id eySrvAoMc09m for ; Tue, 18 Apr 2006 15:30:32 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from 137086.vserver.de (vs137086.vserver.de [62.75.137.86]) by postgresql.org (Postfix) with ESMTP id CD8BE11F6059 for ; Tue, 18 Apr 2006 15:30:31 -0300 (ADT) Received: from a-kretschmer.de (p54B39CFB.dip0.t-ipconnect.de [84.179.156.251]) (authenticated bits=0) by 137086.vserver.de (8.12.8/8.12.8) with ESMTP id k3IIUQ7e023425 for ; Tue, 18 Apr 2006 20:30:27 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 4.61) (envelope-from ) id 1FVuyb-0008MP-Ip for pgsql-sql@postgresql.org; Tue, 18 Apr 2006 20:31:01 +0200 Date: Tue, 18 Apr 2006 20:31:01 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: Looking for some help with cascading updates... Message-ID: <20060418183101.GA31339@KanotixBox> References: <647d31c20604181119m43ba3c7ay3d467dd9446a6fd8@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <647d31c20604181119m43ba3c7ay3d467dd9446a6fd8@mail.gmail.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: mutt-ng 1.5.9i (Linux) X-Archive-Number: 200604/115 X-Sequence-Number: 24924 Mark True schrieb: > > Here is the question: > > I have a situation where I need to create triggers to cascade an insert > operation to many tables to maintain foreign key constraints. > > So at a high level > > INSERT INTO myTable (Name, Address, Zip) VALUES ('Mark', '3 Dingle St.', > '01832') > > myTable has a relation to two other tables, which contain Zip and Address. > Before I insert into myTable I want to: > > Check if '3 Dingle St.' exists in table Address, if not insert it > Check if '01832' exists in table Zip and if not insert it For such task i write a function (plpgsql). This obtains all parameters, do the checks and insert into the other tables and the table with the fk constraints. HTH, Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknow) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°