Re: use null or 0 in foreign key column, to mean "no value"?

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: use null or 0 in foreign key column, to mean "no value"?
Дата
Msg-id E1D87314-AF30-4D8C-B78E-8E369000D861@gmail.com
обсуждение исходный текст
Ответ на use null or 0 in foreign key column, to mean "no value"?  (Robert Nikander <rob.nikander@gmail.com>)
Список pgsql-general
> On 27 Jun 2015, at 5:59, Robert Nikander <rob.nikander@gmail.com> wrote:
> In application code, prepared statements want to say: `select * from items where color_id = ?` and that `?` might be
aint or null, so that doesn’t work.  

You could add another parameter to test which expression to 'activate' in the query, something like:

select * from items where ('notnull' = ? and color_id = ?) or ('null' = ? and color_id is null);

Of course, with those _positional_ query parameters that means you need to add the same value TWICE into the query. You
wouldn'tneed to with _named_ query parameters, if those are available to you. 

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.



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

Предыдущее
От: John McKown
Дата:
Сообщение: Re: use null or 0 in foreign key column, to mean "no value"?
Следующее
От: Gerdan Rezende dos Santos
Дата:
Сообщение: HA