Question

Started by Robert Partykaover 22 years ago7 messagesgeneral
Jump to latest
#1Robert Partyka
bobson@wdg.pl

Hi,

I have question:

why such condition:
foofield not like '%bar%'

where foofield is varchar

returns false (or rather even ignore row) on record where foofield is null
but
returns true on records where foofield is '' (empty string)

regards
Robert

#2Gaetano Mendola
mendola@bigfoot.com
In reply to: Robert Partyka (#1)
Re: Question

Robert Partyka wrote:

Hi,

I have question:

why such condition:
foofield not like '%bar%'

where foofield is varchar

returns false (or rather even ignore row) on record where foofield is null
but
returns true on records where foofield is '' (empty string)

SQL specifications.

Empty string and NULL are two different thinks.

Regards
Gaetano Mendola

#3Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Robert Partyka (#1)
Re: Question

On Mon, 13 Oct 2003, Robert Partyka wrote:

why such condition:
foofield not like '%bar%'

where foofield is varchar

returns false (or rather even ignore row) on record where foofield is
null

Actually, it probably returns unknown(NULL) on such records.
NULL LIKE '%bar%' is unknown, so
NULL NOT LIKE '%bar%' is also unknown.

This is because NULL isn't the same as empty string, nor is it the absence
of a value, but it's an unknown value.

#4Vincent Hikida
vhikida@inreach.com
In reply to: Stephan Szabo (#3)
Re: Question

If you are experienced in Oracle, this might be confusing since Oracle
treats empty string and NULL as being the same.

Show quoted text

On Mon, 13 Oct 2003, Robert Partyka wrote:

why such condition:
foofield not like '%bar%'

where foofield is varchar

returns false (or rather even ignore row) on record where foofield is
null

Actually, it probably returns unknown(NULL) on such records.
NULL LIKE '%bar%' is unknown, so
NULL NOT LIKE '%bar%' is also unknown.

This is because NULL isn't the same as empty string, nor is it the
absence of a value, but it's an unknown value.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

#5Gaetano Mendola
mendola@bigfoot.com
In reply to: Vincent Hikida (#4)
Re: Question

vhikida@inreach.com wrote:

If you are experienced in Oracle, this might be confusing since Oracle
treats empty string and NULL as being the same.

Really? I don't believe it.

Regards
Gaetano Mendola

#6Mike Mascari
mascarm@mascari.com
In reply to: Gaetano Mendola (#5)
Re: Question

Gaetano Mendola wrote:

vhikida@inreach.com wrote:

If you are experienced in Oracle, this might be confusing since Oracle
treats empty string and NULL as being the same.

Really? I don't believe it.

It is insane, but true.

Mike Mascari
mascarm@mascari.com

#7Bruce Momjian
bruce@momjian.us
In reply to: Mike Mascari (#6)
Re: Question

Mike Mascari <mascarm@mascari.com> writes:

Gaetano Mendola wrote:

vhikida@inreach.com wrote:

If you are experienced in Oracle, this might be confusing since Oracle
treats empty string and NULL as being the same.

Really? I don't believe it.

It is insane, but true.

Uh, yeah, but I think that results in the same behaviour for the case at hand.

ie on oracle this is still holds:

NULL LIKE '%foo%' => NULL

The idiocy is that Oracle does this:

'' LIKE '%foo%' => NULL

because it treats '' as if you had NULL, ie, equivalent to the example above.

--
greg