Foreign key check only if not null?

Поиск
Список
Период
Сортировка
От Phoenix Kiula
Тема Foreign key check only if not null?
Дата
Msg-id CAFWfU=voXQ4p2fNqQ=6RtU0uT+SSgf6T+NDWbCrBKV4yW+9YXw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Foreign key check only if not null?
Re: Foreign key check only if not null?
Список pgsql-general
Hi,

I bet this is a simple solution but I have been racking my brains.

I have a column in my table:

    user_id  varchar(100) ;

This can be NULL, or it can have a value. If it has a value during
INSERT or UPDATE, I want to check that the user exists against my
"Users" table. Otherwise, NULL is ok. (Because the functionality in
question is open to both unregistered and registered users).

Any idea on how I can implement a FOREIGN KEY constraint? Or do I need
a pre-insert and pre-update RULE for this?

Thanks!

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Compatibility 9.1rc and 9.1.0
Следующее
От: John R Pierce
Дата:
Сообщение: 9.0, 9.1 RPM based parallel execution?