pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-sql@postgresql.org
Subject: Re: Looking for some help with cascading updates...
Date: Tue, 18 Apr 2006 20:49:59 +0200
Message-ID: <20060418184959.GA2576@KanotixBox> (raw)
In-Reply-To: <647d31c20604181144g63b9ecc2t800e4e2d5fa91f0e@mail.gmail.com>
References: <647d31c20604181119m43ba3c7ay3d467dd9446a6fd8@mail.gmail.com>
	<20060418183101.GA31339@KanotixBox>
	<647d31c20604181144g63b9ecc2t800e4e2d5fa91f0e@mail.gmail.com>

Mark True <darfoo@gmail.com> 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°



view thread (7+ messages)  latest in thread

Message-ID: <20060418184959.GA2576@KanotixBox>
Permalink:  ../20060418184959.GA2576@KanotixBox/
Also on:    postgresql.org/message-id/20060418184959.GA2576@KanotixBox

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: akretschmer@spamfence.net
  Subject: Re: Looking for some help with cascading updates...
  In-Reply-To: <20060418184959.GA2576@KanotixBox>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox