dbTalk Databases Forums  

remove unwanted characters from column during select

comp.databases.mysql comp.databases.mysql


Discuss remove unwanted characters from column during select in the comp.databases.mysql forum.



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

Default remove unwanted characters from column during select - 12-30-2010 , 11:22 AM






Ls,

I want to make a select query.
This query has to match on column x like:
SELECT *
FROM `table`
WHERE `column` LIKE %value%

I only get some of the results I want because the `table` column has
"unwanted" characters in it.

In PHP I could strip the unwanted characters like this:
$table = preg_replace("/\W/", "", $table);

So I thought I could do something like:
SELECT *
FROM `table`
WHERE preg_replace("/\W/", "", `column`) LIKE %value%

But with the php code converted to "MySQL code".
Unfortunatally this has proven to difficult for this (almost) stupid
noob.

Could anyone of you help me with the select query?

Alexander

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

Default Re: remove unwanted characters from column during select - 12-31-2010 , 10:00 PM






In article <8546a170-a6b2-41fa-ab58-cc0db891d19c (AT) j25g2000yqa (DOT) googlegroups.com>, Electricdummy <electricdummy (AT) hotmail (DOT) com> wrote:
Quote:
Ls,

I want to make a select query.
This query has to match on column x like:
SELECT *
FROM `table`
WHERE `column` LIKE %value%

I only get some of the results I want because the `table` column has
"unwanted" characters in it.

In PHP I could strip the unwanted characters like this:
$table = preg_replace("/\W/", "", $table);

So I thought I could do something like:
SELECT *
FROM `table`
WHERE preg_replace("/\W/", "", `column`) LIKE %value%

But with the php code converted to "MySQL code".
Unfortunatally this has proven to difficult for this (almost) stupid
noob.

Could anyone of you help me with the select query?
Perhaps if you'd be good enough to explain:
1. What you've already tried
2. What happens when you try it
3. What, exactly, are the "unwanted characters" you need to ignore, and where
do they occur?











Quote:
Alexander

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

Default Re: remove unwanted characters from column during select - 01-02-2011 , 03:20 AM



On 1 jan, 05:00, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
In article <8546a170-a6b2-41fa-ab58-cc0db891d... (AT) j25g2000yqa (DOT) googlegroups..com>, Electricdummy <electricdu... (AT) hotmail (DOT) com> wrote:





Ls,

I want to make a select query.
This query has to match on column x like:
SELECT *
FROM `table`
WHERE `column` LIKE %value%

I only get some of the results I want because the `table` column has
"unwanted" characters in it.

In PHP I could strip the unwanted characters like this:
* *$table = preg_replace("/\W/", "", $table);

So I thought I could do something like:
SELECT *
FROM `table`
WHERE preg_replace("/\W/", "", `column`) LIKE %value%

But with the php code converted to "MySQL code".
Unfortunatally this has proven to difficult for this (almost) stupid
noob.

Could anyone of you help me with the select query?

Perhaps if you'd be good enough to explain:
1. What you've already tried
2. What happens when you try it
3. What, exactly, are the "unwanted characters" you need to ignore, and where
do they occur?



1. actualy nothing except some small tests on parts of the query in
MySQL since I already knew it wouldn't work.
In PHP I did the select with a regex and it worked (slow) and the
table is growing.
2. I got no rows or all rows back or in most cases an error.
3. The "unwanted characters" are all non-alfanumeric charactars, so
the only wanted characters are: A-Z, a-z and 0-9.
The "unwanted characters occur "at random", so not on a specific place
in the field (that would have been way too easy) and in some cases not
at all.

A "special" thing I tried but actually didn't want to do is make an
extra column with "the same field" stripped from the "unwanted
characters", this worked (including filling them with the data through
a query) except for filling them with a trigger (triggers seems not to
be allowed by the provider). Since I have no control over the input I
cannot change that script to fill the extra field.

Alexander

Reply With Quote
  #4  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: remove unwanted characters from column during select - 01-03-2011 , 02:41 AM



El 30/12/2010 18:22, Electricdummy escribió/wrote:
Quote:
I want to make a select query.
This query has to match on column x like:
SELECT *
FROM `table`
WHERE `column` LIKE %value%

I only get some of the results I want because the `table` column has
"unwanted" characters in it.

In PHP I could strip the unwanted characters like this:
$table = preg_replace("/\W/", "", $table);

So I thought I could do something like:
SELECT *
FROM `table`
WHERE preg_replace("/\W/", "", `column`) LIKE %value%

But with the php code converted to "MySQL code".
Unfortunatally this has proven to difficult for this (almost) stupid
noob.
If I recall correctly, there isn't a MySQL equivalent to PHP's
preg_replace(). You can use regular expressions to perform matches but
no replacements. However, if you can produce an addecuate expression
that should be enough:

http://dev.mysql.com/doc/refman/5.1/en/regexp.html

Whatever, it's going to be very slow.

Assuming you have a valid reason to make "tool" match with "into old",
my advice is to add a secondary column you your table to serve as
pseudo-index and use your client-side language to keep it updated every
time you insert or update a row.



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

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.