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 CE99711F6767 for ; Tue, 18 Apr 2006 15:49:31 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0.213 X-Spam-Level: X-Spam-Status: No, score=0.213 required=5 tests=[AWL=0.213] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id IFg4G7I5eAzt for ; Tue, 18 Apr 2006 15:49:26 -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 7F0DF11F6705 for ; Tue, 18 Apr 2006 15:49:27 -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 k3IInN9a014150 for ; Tue, 18 Apr 2006 20:49:24 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 4.61) (envelope-from ) id 1FVvGx-0000rs-Ar for pgsql-sql@postgresql.org; Tue, 18 Apr 2006 20:49:59 +0200 Date: Tue, 18 Apr 2006 20:49:59 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: Looking for some help with cascading updates... Message-ID: <20060418184959.GA2576@KanotixBox> References: <647d31c20604181119m43ba3c7ay3d467dd9446a6fd8@mail.gmail.com> <20060418183101.GA31339@KanotixBox> <647d31c20604181144g63b9ecc2t800e4e2d5fa91f0e@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: <647d31c20604181144g63b9ecc2t800e4e2d5fa91f0e@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/117 X-Sequence-Number: 24926 Mark True schrieb: > I guess I should have clarified. I am having trouble figuring out how to > construct the IF statement to see if that item exists in the foreign table > something like: > > count=select count(*) from table; > > if count=0 { > insert fkey into myOtherTable > } a real example: (table harz_ufpos references harz_uf) create or replace function gh_insert(text,int,int,text,int,float) returns int as $$ declare c int; begin select into c count(*) from harz_uf where (uf,ab) = ($1,$2); if c = 0 then insert into harz_uf (uf,ab,beschreibung,aktiv) values ($1,$2,$4,'t'); end if; insert into harz_ufpos (uf,pos,anzahl,rest,flaeche) values ($1,$3,$5,$5,$6); return 1; end; $$ language 'plpgsql'; 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°