From: Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>
To: Vick Khera <vivek@khera.org>
Cc: pgsql-sql@postgresql.org, pgsql-general <pgsql-general@postgresql.org>
Subject: Re: [GENERAL] foreign key to multiple tables depending on another column's value
Date: Wed, 29 May 2013 13:14:00 -0300
Message-ID: <51A62948.4040603@gmail.com> (raw)
In-Reply-To: <CALd+dcdyGn12Fbmyhpau6JvfB3MiiiYvXCH2WbFWFHoSN-P7Lg@mail.gmail.com>
References: <51A60971.8060608@gmail.com>
<CALd+dcdyGn12Fbmyhpau6JvfB3MiiiYvXCH2WbFWFHoSN-P7Lg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
Em 29-05-2013 12:51, Vick Khera escreveu:
>
> On Wed, May 29, 2013 at 9:58 AM, Rodrigo Rosenfeld Rosas
> <rr.rosas@gmail.com <mailto:rr.rosas@gmail.com>> wrote:
>
> I know I could use a trigger, or some check constraint maybe, to
> ensure the field exists upon insert (or update), but I can't
> ensure the database will become inconsistent in case I remove a
> mapped field from the other schema.
>
> Now I can finally explain my question: is it possible that I set
> some sort of foreign key whose referenced table and column would
> depend on the value of another column?
>
>
> The FK tests are basically triggers, but highly optimized.
>
> That said, the way they enforce the integrity is by having a trigger
> on both tables. So for your custom need here, you would want to put a
> trigger on the referenced table to disallow deleting a value that is
> still referenced, or do whatever appropriate action upon delete/update
> your application needs.
>
Ok, thanks. I just wanted to be sure there wasn't some hidden feature of
PostgreSQL I wasn't aware of yet...
You know, I'm always learning something new on PG, so it worths trying
to ask first ;)
Cheers,
Rodrigo.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: rr.rosas@gmail.com, vivek@khera.org, pgsql-general@postgresql.org
Subject: Re: [GENERAL] foreign key to multiple tables depending on another column's value
In-Reply-To: <51A62948.4040603@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox