Re: Foreign Key with an "OR" condition (and two concatenated columns)?

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Foreign Key with an "OR" condition (and two concatenated columns)?
Дата
Msg-id 22A8FB55-FD19-41A4-934B-183FF688522B@yahoo.com
обсуждение исходный текст
Ответ на Foreign Key with an "OR" condition (and two concatenated columns)?  (Phoenix Kiula <phoenix.kiula@gmail.com>)
Список pgsql-general
On Jan 8, 2012, at 9:33, Phoenix Kiula <phoenix.kiula@gmail.com> wrote:

> Hi. Hope I'm articulating the question correctly.
>
> I currently have a foreign key like this:
>
>    "fk_table2" FOREIGN KEY (id) REFERENCES table1(id) ON DELETE CASCADE;
>
> Given the peculiar needs of this db, it seems that in some cases we
> will need to track the "id" of table2 against a concatenation of two
> columns in table2. So in pseudocode, it would look something like
> this.
>
>    "fk_table2" FOREIGN KEY (id) REFERENCES table1(id   OR
> id||'.'||column2) ON DELETE CASCADE;
>
> Do I need a separate constraint for this?
>
> Many thanks for any pointers!
>
>

Assuming you actually tried your syntax and received an error...

You cannot have two mutually exclusive constraints since one would always fail.  You need to modify you schema to
conformto the definition of a FOREGIN KEY or maintain integrity via a trigger. 

Not enough details to comment on whether what you think you need is indeed a good design choice.

Database needs are nice in that they can be changed without much argument from the database.  Now, if other developers
exhibitthese needs then your work becomes more difficult. 

David J.

В списке pgsql-general по дате отправления:

Предыдущее
От: Phoenix Kiula
Дата:
Сообщение: Foreign Key with an "OR" condition (and two concatenated columns)?
Следующее
От: Stefan Keller
Дата:
Сообщение: Re: Binary Large Objects (LOB/BLOB) in Hibernate and JDBC: Unresolved issues