Re: Looking for some help with cascading updates...

From: "Mark True" <darfoo(at)gmail(dot)com>
To: "Andreas Kretschmer" <akretschmer(at)spamfence(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Looking for some help with cascading updates...
Date: 2006-04-18 18:44:29
Message-ID: 647d31c20604181144g63b9ecc2t800e4e2d5fa91f0e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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
}

On 4/18/06, Andreas Kretschmer <akretschmer(at)spamfence(dot)net> wrote:
>
> Mark True <darfoo(at)gmail(dot)com> 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°
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Kretschmer 2006-04-18 18:49:59 Re: Looking for some help with cascading updates...
Previous Message Ron Peterson 2006-04-18 18:42:10 create temp table in rule