Re: Query

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Pedro Igor <pedroigor(at)aip(dot)com(dot)br>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Query
Date: 2003-01-03 15:57:45
Message-ID: 20030103075235.Q3488-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Fri, 3 Jan 2003, Pedro Igor wrote:

> Regards .....
>
> I hope someone can help me in this query.
> Have a field in a table that needs to check if another table has the value that is being inserted.
> Ex:
> table A
> - id int constraint pkey_id primary key,
>
>
> table B
> - id int constraint fkey_A_B references A,
>
> Here comes my doubt:
>
> table C
> - id int constraint fkey_A_C references A check (if exists B.id
> = C.id)
>
> How can i build this expression so, when I insert a tupple in
> table C the field will check in the table A(ok, because is a foreign
> key) and also in table B ....

If you only want insert(/update) time checks (ie that deleting from B
doesn't violate) then a trigger should work. I think a check constraint
to a function that does the work will work as well. Subsellects in check
constraints are a nasty problem that hasn't been solved yet (since those
do imply the inverse constraint).

Of course if you want two foreign keys you should be able to do that as
well.

In response to

  • Query at 2003-01-03 13:46:27 from Pedro Igor

Browse pgsql-sql by date

  From Date Subject
Next Message Daniel Bruce Lynes 2003-01-03 17:27:28 Compiling pl/pgsql functions?
Previous Message Pedro Igor 2003-01-03 13:46:27 Query