PB with Null string

Started by Gilles Daroldover 27 years ago3 messagesgeneral
Jump to latest
#1Gilles Darold
darold@neptune.fr

Hi,

I have tried this query to check if a field is empty:

SELECT * FROM t_table WHERE s_string='';

where s_string is declared as text. But this doesn't work, why? Is
there's an
other way to do that ? I have also tried with NULL but I think it is not
included
in the 6.3.2...

Thank,

Gilles

#2Postgres DBA
postgres@nest.bistbn.com
In reply to: Gilles Darold (#1)
Re: [GENERAL] PB with Null string

Instead you should use "IS NOT NULL" or "IS NULL":
SELECT * FROM t_table WHERE s_string IS NULL;

Aleksey

On Wed, 23 Dec 1998, darold wrote:

Show quoted text

Hi,

I have tried this query to check if a field is empty:

SELECT * FROM t_table WHERE s_string='';

where s_string is declared as text. But this doesn't work, why? Is
there's an
other way to do that ? I have also tried with NULL but I think it is not
included
in the 6.3.2...

Thank,

Gilles

#3Herouth Maoz
herouth@oumail.openu.ac.il
In reply to: Gilles Darold (#1)
Re: [GENERAL] PB with Null string

(Redirected to the SQL list):

At 11:26 +0200 on 23/12/98, darold wrote:

I have tried this query to check if a field is empty:

SELECT * FROM t_table WHERE s_string='';

where s_string is declared as text. But this doesn't work, why? Is
there's an
other way to do that ? I have also tried with NULL but I think it is not
included
in the 6.3.2...

There is a difference between the empty string and NULL. NULL means there
is no value in the field. The empty string means there is a value, and this
value is ''.

To check for nulls, you don't write s_string=NULL. This, unfortunately,
doesn't work in Postgres, because two NULLs are not considered equal. What
you should do is s_string IS NULL:

SELECT * FROM t_table WHERE s_string IS NULL;

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma