dbTalk Databases Forums  

like ""?

comp.databases.mysql comp.databases.mysql


Discuss like ""? in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SpreadTooThin
 
Posts: n/a

Default like ""? - 03-01-2011 , 02:13 PM






What does the 'like' expression look like for a zero length string?

select * from x where something Like %%

Reply With Quote
  #2  
Old   
Doug Miller
 
Posts: n/a

Default Re: like ""? - 03-01-2011 , 03:17 PM






In article <b8a5b877-d51b-4742-bb6e-cd3376dda29e (AT) 8g2000prb (DOT) googlegroups.com>, SpreadTooThin <bjobrien62 (AT) gmail (DOT) com> wrote:
Quote:
What does the 'like' expression look like for a zero length string?

select * from x where something Like %%
Think about it a little bit...

If you're trying to match a zero-length string, why would you use LIKE at all?
There's no "pattern" to match, only an exact value. So the answer to your
question is,
SELECT * FROM x WHERE something = '';

Reply With Quote
  #3  
Old   
onedbguru
 
Posts: n/a

Default Re: like ""? - 03-01-2011 , 06:37 PM



On Mar 1, 4:17*pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
In article <b8a5b877-d51b-4742-bb6e-cd3376dda... (AT) 8g2000prb (DOT) googlegroups.com>, SpreadTooThin <bjobrie... (AT) gmail (DOT) com> wrote:

What does the 'like' expression look like for a zero length string?

select * from x where something Like %%

Think about it a little bit...

If you're trying to match a zero-length string, why would you use LIKE atall?
There's no "pattern" to match, only an exact value. So the answer to your
question is,
SELECT * FROM x WHERE something = '';

You need to be careful with inserting "emtpy" strings. If you used
the \where something=''/ would return no rows as it equates empty
string '' as NULL. You would get the correct results if you used
"where something is NULL;" My "MySQL" system is currently unavailable
to test how it behaves.

Reply With Quote
  #4  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: like ""? - 03-01-2011 , 07:03 PM



On 3/1/2011 7:37 PM, onedbguru wrote:
Quote:
On Mar 1, 4:17 pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
In article<b8a5b877-d51b-4742-bb6e-cd3376dda... (AT) 8g2000prb (DOT) googlegroups.com>, SpreadTooThin<bjobrie... (AT) gmail (DOT) com> wrote:

What does the 'like' expression look like for a zero length string?

select * from x where something Like %%

Think about it a little bit...

If you're trying to match a zero-length string, why would you use LIKE at all?
There's no "pattern" to match, only an exact value. So the answer to your
question is,
SELECT * FROM x WHERE something = '';


You need to be careful with inserting "emtpy" strings. If you used
the \where something=''/ would return no rows as it equates empty
string '' as NULL. You would get the correct results if you used
"where something is NULL;" My "MySQL" system is currently unavailable
to test how it behaves.
Incorrect. '' is an empty string, not a NULL value. If you insert an
empty string, WHERE something IS NULL will NOT return the row. However,
WHERE something = '' will return the row.

If you want a null value in a field, use NULL. It is specifically the
lack of a value; an empty string is a value. Two different things.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #5  
Old   
The Natural Philosopher
 
Posts: n/a

Default Re: like ""? - 03-01-2011 , 07:05 PM



onedbguru wrote:
Quote:
On Mar 1, 4:17 pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
In article <b8a5b877-d51b-4742-bb6e-cd3376dda... (AT) 8g2000prb (DOT) googlegroups.com>, SpreadTooThin <bjobrie... (AT) gmail (DOT) com> wrote:

What does the 'like' expression look like for a zero length string?
select * from x where something Like %%
Think about it a little bit...

If you're trying to match a zero-length string, why would you use LIKE at all?
There's no "pattern" to match, only an exact value. So the answer to your
question is,
SELECT * FROM x WHERE something = '';


You need to be careful with inserting "emtpy" strings. If you used
the \where something=''/ would return no rows as it equates empty
string '' as NULL. You would get the correct results if you used
"where something is NULL;" My "MySQL" system is currently unavailable
to test how it behaves.
IME NULL is not the same as a zero length string at all.

Upate..set (field1=NULL) seems to give a different value from set(field1='')

I have had some weird an interesting bugs because of this.

Reply With Quote
  #6  
Old   
onedbguru
 
Posts: n/a

Default Re: like ""? - 03-02-2011 , 05:48 PM



On Mar 1, 8:05*pm, The Natural Philosopher <t... (AT) invalid (DOT) invalid>
wrote:
Quote:
onedbguru wrote:
On Mar 1, 4:17 pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
In article <b8a5b877-d51b-4742-bb6e-cd3376dda... (AT) 8g2000prb (DOT) googlegroups.com>, SpreadTooThin <bjobrie... (AT) gmail (DOT) com> wrote:

What does the 'like' expression look like for a zero length string?
select * from x where something Like %%
Think about it a little bit...

If you're trying to match a zero-length string, why would you use LIKEat all?
There's no "pattern" to match, only an exact value. So the answer to your
question is,
SELECT * FROM x WHERE something = '';

You need to be careful with inserting "emtpy" strings. *If you used
the \where something=''/ *would return no rows as it equates empty
string '' as NULL. *You would get the correct results if you used
"where something is NULL;" *My "MySQL" system is currently unavailable
to test how it behaves.

IME NULL is not the same as a zero length string at all.

Upate..set (field1=NULL) seems to give a different value from set(field1='')

I have had some weird an interesting bugs because of this.
All that I was saying was that you need to be careful... Not all
database engines treat empty string the same as null. Not saying that
it is correct behavior, but there are db engines out there that an
empty string is equal to NULL value. There are tons of articles
written on the treatment of ES vs NULL and you can look them up.

In MySQL, it would be interesting to dump the data block to see what
is actually stored on disk to differentiate ES vs NULL. In some
{unnamed} database engines, no value is stored as HEX 00 (aka
NULL).

Reply With Quote
  #7  
Old   
SpreadTooThin
 
Posts: n/a

Default Re: like ""? - 03-02-2011 , 06:13 PM



On Mar 2, 4:48*pm, onedbguru <onedbg... (AT) yahoo (DOT) com> wrote:
Quote:
On Mar 1, 8:05*pm, The Natural Philosopher <t... (AT) invalid (DOT) invalid
wrote:



onedbguru wrote:
On Mar 1, 4:17 pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
In article <b8a5b877-d51b-4742-bb6e-cd3376dda... (AT) 8g2000prb (DOT) googlegroups.com>, SpreadTooThin <bjobrie... (AT) gmail (DOT) com> wrote:

What does the 'like' expression look like for a zero length string?
select * from x where something Like %%
Think about it a little bit...

If you're trying to match a zero-length string, why would you use LIKE at all?
There's no "pattern" to match, only an exact value. So the answer toyour
question is,
SELECT * FROM x WHERE something = '';

You need to be careful with inserting "emtpy" strings. *If you used
the \where something=''/ *would return no rows as it equates empty
string '' as NULL. *You would get the correct results if you used
"where something is NULL;" *My "MySQL" system is currently unavailable
to test how it behaves.

IME NULL is not the same as a zero length string at all.

Upate..set (field1=NULL) seems to give a different value from set(field1='')

I have had some weird an interesting bugs because of this.

All that I was saying was that you need to be careful... Not all
database engines treat empty string the same as null. Not saying that
it is correct behavior, but there are db engines out there that an
empty string is equal to NULL value. *There are tons of articles
written on the treatment of ES vs NULL and you can look them up.

In MySQL, it would be interesting to dump the data block to see what
is actually stored on disk to differentiate ES vs NULL. *In some
{unnamed} *database engines, no value is stored as HEX 00 (aka
NULL).
Right.. That's why I wanted it to be LIKE '%%' and not = ''

Reply With Quote
  #8  
Old   
Doug Miller
 
Posts: n/a

Default Re: like ""? - 03-02-2011 , 06:20 PM



In article <2f1a0dcb-34ff-479f-9458-0d6707af887b (AT) v16g2000vbq (DOT) googlegroups.com>, onedbguru <onedbguru (AT) yahoo (DOT) com> wrote:
Quote:
On Mar 1, 8:05=A0pm, The Natural Philosopher <t... (AT) invalid (DOT) invalid
wrote:
onedbguru wrote:
On Mar 1, 4:17 pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
In article <b8a5b877-d51b-4742-bb6e-cd3376dda... (AT) 8g2000prb (DOT) googlegroup=
s.com>, SpreadTooThin <bjobrie... (AT) gmail (DOT) com> wrote:

What does the 'like' expression look like for a zero length string?
select * from x where something Like %%
Think about it a little bit...

If you're trying to match a zero-length string, why would you use LIKE=
at all?
There's no "pattern" to match, only an exact value. So the answer to y=
our
question is,
SELECT * FROM x WHERE something =3D '';

You need to be careful with inserting "emtpy" strings. =A0If you used
the \where something=3D''/ =A0would return no rows as it equates empty
string '' as NULL. =A0You would get the correct results if you used
"where something is NULL;" =A0My "MySQL" system is currently unavailabl=
e
to test how it behaves.

IME NULL is not the same as a zero length string at all.

Upate..set (field1=3DNULL) seems to give a different value from set(field=
1=3D'')

I have had some weird an interesting bugs because of this.

All that I was saying was that you need to be careful... Not all
database engines treat empty string the same as null.
In fact, most don't.

Reply With Quote
  #9  
Old   
Doug Miller
 
Posts: n/a

Default Re: like ""? - 03-02-2011 , 06:39 PM



In article <d2eff590-5193-4a65-9632-eb4a111a261a (AT) q12g2000prb (DOT) googlegroups.com>, SpreadTooThin <bjobrien62 (AT) gmail (DOT) com> wrote:
Quote:
On Mar 2, 4:48=A0pm, onedbguru <onedbg... (AT) yahoo (DOT) com> wrote:
On Mar 1, 8:05=A0pm, The Natural Philosopher <t... (AT) invalid (DOT) invalid
wrote:



onedbguru wrote:
On Mar 1, 4:17 pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
In article <b8a5b877-d51b-4742-bb6e-cd3376dda... (AT) 8g2000prb (DOT) googlegro=
ups.com>, SpreadTooThin <bjobrie... (AT) gmail (DOT) com> wrote:

What does the 'like' expression look like for a zero length string?
select * from x where something Like %%
Think about it a little bit...

If you're trying to match a zero-length string, why would you use LI=
KE at all?
There's no "pattern" to match, only an exact value. So the answer to=
your
question is,
SELECT * FROM x WHERE something =3D '';

You need to be careful with inserting "emtpy" strings. =A0If you used
the \where something=3D''/ =A0would return no rows as it equates empt=
y
string '' as NULL. =A0You would get the correct results if you used
"where something is NULL;" =A0My "MySQL" system is currently unavaila=
ble
to test how it behaves.

IME NULL is not the same as a zero length string at all.

Upate..set (field1=3DNULL) seems to give a different value from set(fie=
ld1=3D'')

I have had some weird an interesting bugs because of this.

All that I was saying was that you need to be careful... Not all
database engines treat empty string the same as null. Not saying that
it is correct behavior, but there are db engines out there that an
empty string is equal to NULL value. There are tons of articles
written on the treatment of ES vs NULL and you can look them up.

In MySQL, it would be interesting to dump the data block to see what
is actually stored on disk to differentiate ES vs NULL. In some
{unnamed} database engines, no value is stored as HEX 00 (aka
NULL).

Right.. That's why I wanted it to be LIKE '%%' and not = ''

What, so you could match a NULL? Won't work. No LIKE predicate will ever match
NULL. The only way to match NULL is with the IS NULL predicate.

Moreover, no LIKE predicate containing '%' will ever match *only* an empty
string, either.

mysql> create table foo (bar decimal, fubar varchar(10));
Query OK, 0 rows affected (0.05 sec)

mysql> insert into foo values (1, '');
Query OK, 1 row affected (0.00 sec)

mysql> insert into foo values (2, NULL);
Query OK, 1 row affected (0.00 sec)

mysql> insert into foo values (3, 'abc');
Query OK, 1 row affected (0.00 sec)

mysql> select * from foo where fubar like '%';
+------+-------+
Quote:
bar | fubar |
+------+-------+
1 | |
3 | abc |
+------+-------+
2 rows in set (0.01 sec)

mysql> select * from foo where fubar = '';
+------+-------+
Quote:
bar | fubar |
+------+-------+
1 | |
+------+-------+
1 row in set (0.00 sec)

mysql> select * from foo where fubar is null;
+------+-------+
Quote:
bar | fubar |
+------+-------+
2 | NULL |
+------+-------+
1 row in set (0.00 sec)

Reply With Quote
  #10  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: like ""? - 03-02-2011 , 10:20 PM



On 3/2/2011 6:48 PM, onedbguru wrote:
Quote:
On Mar 1, 8:05 pm, The Natural Philosopher<t... (AT) invalid (DOT) invalid
wrote:
onedbguru wrote:
On Mar 1, 4:17 pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
In article<b8a5b877-d51b-4742-bb6e-cd3376dda... (AT) 8g2000prb (DOT) googlegroups.com>, SpreadTooThin<bjobrie... (AT) gmail (DOT) com> wrote:

What does the 'like' expression look like for a zero length string?
select * from x where something Like %%
Think about it a little bit...

If you're trying to match a zero-length string, why would you use LIKE at all?
There's no "pattern" to match, only an exact value. So the answer to your
question is,
SELECT * FROM x WHERE something = '';

You need to be careful with inserting "emtpy" strings. If you used
the \where something=''/ would return no rows as it equates empty
string '' as NULL. You would get the correct results if you used
"where something is NULL;" My "MySQL" system is currently unavailable
to test how it behaves.

IME NULL is not the same as a zero length string at all.

Upate..set (field1=NULL) seems to give a different value from set(field1='')

I have had some weird an interesting bugs because of this.

All that I was saying was that you need to be careful... Not all
database engines treat empty string the same as null. Not saying that
it is correct behavior, but there are db engines out there that an
empty string is equal to NULL value. There are tons of articles
written on the treatment of ES vs NULL and you can look them up.

Any database which adheres to the SQL standards does.

Quote:
In MySQL, it would be interesting to dump the data block to see what
is actually stored on disk to differentiate ES vs NULL. In some
{unnamed} database engines, no value is stored as HEX 00 (aka
NULL).

No, hex(00) is NOT the same as NULL. As anyone who proports himself to
be a "db guru" should know.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.