Re: REFERENCES

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Andre Schubert <andre(dot)schubert(at)km3(dot)de>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: REFERENCES
Date: 2002-03-13 15:57:04
Message-ID: 20020313075206.L81426-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Wed, 13 Mar 2002, Andre Schubert wrote:

> Hi to all,
>
> i have a simple problem and wont request assistance fro m this list.
> i have to tables
>
> foo:
> id int8 UNIQUE
>
> bar:
> id int8 UNIQUE
> foo_id int8
>
> Now i wont foo_id to be a id which exists in the foo, this could be done
> with foo_id REFERENCES foo (id).
> But what should i do if i want foo_id to be a id existing in foo or to
> be zero(0).
> I have created a view as "select id from foo UNION select 0" and tried
> to REFERENCE against this view, but that
> doesnt work.

Correct, because you cannot currently reference a view. Currently you
can't do that via just a references constraint, you'd need to make
triggers that do the work of the checks.

Why can't you reference a view? Well, the reason for that is that we'd
need to be able to figure out how to do the referential action checks
against the real tables referenced by the view. Even if we put triggers
on all data changing operations on each of the tables it's not necessarily
easy to work out what row(s) of the view are being changed by the
operation. I don't think this is likely to be changed anytime soon.

In response to

  • REFERENCES at 2002-03-13 10:53:29 from Andre Schubert

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2002-03-13 16:02:28 Re: ALTER CONSTRAINT FOREIGN KEY
Previous Message Bo Lorentsen 2002-03-13 15:35:37 Re: Large data sets and FOR LOOP's