From: | Andreas Kretschmer <akretschmer(at)spamfence(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Looking for some help with cascading updates... |
Date: | 2006-04-18 18:49:59 |
Message-ID: | 20060418184959.GA2576@KanotixBox |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Mark True <darfoo(at)gmail(dot)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°
From | Date | Subject | |
---|---|---|---|
Next Message | Mark True | 2006-04-18 19:08:59 | Re: Looking for some help with cascading updates... |
Previous Message | Mark True | 2006-04-18 18:44:29 | Re: Looking for some help with cascading updates... |