Re: where with NULL values are not selected

Поиск
Список
Период
Сортировка
От Düster Horst
Тема Re: where with NULL values are not selected
Дата
Msg-id 5B025B1F39D6D4119F5700508BEEEC6603DE3D96@srsofaioi4546.ktso.ch
обсуждение исходный текст
Ответ на where with NULL values are not selected  (Düster Horst <Horst.Duester@bd.so.ch>)
Список pgsql-admin
The problem is solved. The coalesce() function was the solution. Thank you
very much for your input.

With best regards

Horst Düster

---------------------------------
 
Dr. Horst Düster
GIS-Koordinator /Amtschef Stv.

Kanton Solothurn 
Amt für Geoinformation
Abteilung SO!GIS Koordination
Werkhofstr. 65
CH-4509 Solothurn

Tel.: ++41 (0)32 627 25 32
Fax: ++41 (0)32 627 22 14

horst.duester@bd.so.ch
www.sogis.so.ch



-----Ursprüngliche Nachricht-----
Von: Dawid Kuroczko [mailto:qnex42@gmail.com]
Gesendet am: Freitag, 8. Juli 2005 11:08
An: Düster Horst
Cc: pgsql-admin@postgresql.org
Betreff: Re: [ADMIN] where with NULL values are not selected

On 7/8/05, Düster Horst <Horst.Duester@bd.so.ch> wrote:
> I try to join two tables whereas some column values do have NULL values
with
> the following query:
>
> select table1.column from table1, table2 where table1.column=table2.column
>
> table1.column and table2.column may have NULL values. The problem is that
> these columns where not selected. Does there exists any solution to
> select/join the NULL value colums also.

A hint:
qnex=# SELECT 'ok' WHERE NULL=NULL;
?column?
(0 rows)

In other words -- NULL is not equal to NULL.  NULL is not a value, NULL
is a state.  If you want to join those columns, you cannot use NULL
as a joining key.  It's the way SQL works.

Anyway, a quick-and-dirty solution might be:

select table1.column from table1, table2 where
coalesce(table1.column,-1)=coalesce(table2.column, -1);

...assuming column doesn't have '-1' value.

A better solution would be to rethink your design (don't use NULLs).


Incientally, instead of using this syntax:
select table1.column from table1, table2 where table1.column=table2.column;
...try using explicit inner joins:
select table1.column from table1 JOIN table2 USING(column);

Regards,
    Dawid

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

Предыдущее
От: nandan bsd
Дата:
Сообщение: Regarding a backup scenario
Следующее
От: Aris Aridis
Дата:
Сообщение: ...