Skip site navigation (1) Skip section navigation (2)

Looking for some help with cascading updates...

From: "Mark True" <darfoo(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Looking for some help with cascading updates...
Date: 2006-04-18 18:19:20
Message-ID: 647d31c20604181119m43ba3c7ay3d467dd9446a6fd8@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
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

I want to generalize this so that for any insert into myTable, I guarantee
that if Zip and Address are not populated they will be.  My insert into
myTable always contains full information required for doing the inserts into
the other related tables.

Help?

--Mark

Responses

pgsql-sql by date

Next:From: Mark LewisDate: 2006-04-18 18:24:51
Subject: Re: [JDBC] [SQL] Thoughts on a Isolation/Security problem.
Previous:From: Markus SchaberDate: 2006-04-18 12:05:27
Subject: Migrating a Database to a new tablespace

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group