Re: Quick question re foreign keys.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Quick question re foreign keys.
Дата
Msg-id 21715.1193193880@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Quick question re foreign keys.  (Paul Lambert <paul.lambert@autoledgers.com.au>)
Ответы Re: Quick question re foreign keys.  (Paul Lambert <paul.lambert@autoledgers.com.au>)
Список pgsql-sql
Paul Lambert <paul.lambert@autoledgers.com.au> writes:
> I have a table where one column references by foreign key a column from 
> another table. However, the column in this first table does not always 
> contain data which results in a not-null constraint violation when I 
> attempt an insert.

> My question therefore is, is it possible to create a foreign key that is 
> conditional, i.e. only enforce the foreign key where the value in that 
> table is not null.

If I'm understanding you correctly, the problem is not the foreign key,
it's that you marked the column NOT NULL.  A foreign key constraint by
itself will allow a NULL in the referencing column to pass.  You choose
whether you want to allow that or not by separately applying a NOT NULL
constraint or not.
        regards, tom lane


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

Предыдущее
От: "Phillip Smith"
Дата:
Сообщение: Re: Quick question re foreign keys.
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: request for help with COPY syntax