Bluehost.com Web Hosting $6.95

replace query

This is a discussion on replace query within the MySQL Database forums, part of the Database Forums category; I been playing with this for awhile, but can't seem to successfully execute a simple replace query with MySQL ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-08-2007
Bosconian
 
Posts: n/a
Default replace query

I been playing with this for awhile, but can't seem to successfully execute
a simple replace query with MySQL 4.1.12 via phpMyAdmin 2.7.0-pl2

The table only contains around 650 records, yet the query just hangs.

I came across this syntax example:

update [table_name] set [field_name] =
replace([field_name],'[string_to_find]','[string_to_replace]');

My real world usage is:

UPDATE attachments SET fileloc = REPLACE(fileloc,'2001','2001\');

where the backslash is added after the 4-digit year.

An example piece of fileloc data looks like "2001DOM-MK008-C.PDF". The
column is defined as varchar(50).

Any suggestions would be greatly appreciated.


Reply With Quote
  #2 (permalink)  
Old 02-08-2007
Captain Paralytic
 
Posts: n/a
Default Re: replace query

On 8 Feb, 03:38, "Bosconian" <nob...@nowhere.com> wrote:
> I been playing with this for awhile, but can't seem to successfully execute
> a simple replace query with MySQL 4.1.12 via phpMyAdmin 2.7.0-pl2
>
> The table only contains around 650 records, yet the query just hangs.
>
> I came across this syntax example:
>
> update [table_name] set [field_name] =
> replace([field_name],'[string_to_find]','[string_to_replace]');
>
> My real world usage is:
>
> UPDATE attachments SET fileloc = REPLACE(fileloc,'2001','2001\');
>
> where the backslash is added after the 4-digit year.
>
> An example piece of fileloc data looks like "2001DOM-MK008-C.PDF". The
> column is defined as varchar(50).
>
> Any suggestions would be greatly appreciated.


Try doubling up your backslash thus:
UPDATE attachments SET fileloc = REPLACE(fileloc,'2001','2001\\');

Reply With Quote
  #3 (permalink)  
Old 02-08-2007
Sean
 
Posts: n/a
Default Re: replace query


"Bosconian" <nobody@nowhere.com> wrote in message
news:9q-dneNpi8O2BlfYnZ2dnUVZ_smonZ2d@comcast.com...
>I been playing with this for awhile, but can't seem to successfully execute
>a simple replace query with MySQL 4.1.12 via phpMyAdmin 2.7.0-pl2
>
> The table only contains around 650 records, yet the query just hangs.
>
> I came across this syntax example:
>
> update [table_name] set [field_name] =
> replace([field_name],'[string_to_find]','[string_to_replace]');
>
> My real world usage is:
>
> UPDATE attachments SET fileloc = REPLACE(fileloc,'2001','2001\');
>
> where the backslash is added after the 4-digit year.
>
> An example piece of fileloc data looks like "2001DOM-MK008-C.PDF". The
> column is defined as varchar(50).
>
> Any suggestions would be greatly appreciated.
>
>


You're getting into a neverending loop

2001DOM-MK008-C.PDF becomes 2001\DOM-MK008-C.PDF
2001\DOM-MK008-C.PDF becomes 2001\\DOM-MK008-C.PDF
2001\\DOM-MK008-C.PDF becomes 2001\\\DOM-MK008-C.PDF

Try :

UPDATE attachments SET fileloc = REPLACE(fileloc,'2001','test\');

followed by

UPDATE attachments SET fileloc = REPLACE(fileloc,'test\','2001\');



Reply With Quote
  #4 (permalink)  
Old 02-08-2007
Bosconian
 
Posts: n/a
Default Re: replace query

"Captain Paralytic" <paul_lautman@yahoo.com> wrote in message
news:1170926173.684834.299100@a34g2000cwb.googlegr oups.com...
> On 8 Feb, 03:38, "Bosconian" <nob...@nowhere.com> wrote:
>> I been playing with this for awhile, but can't seem to successfully
>> execute
>> a simple replace query with MySQL 4.1.12 via phpMyAdmin 2.7.0-pl2
>>
>> The table only contains around 650 records, yet the query just hangs.
>>
>> I came across this syntax example:
>>
>> update [table_name] set [field_name] =
>> replace([field_name],'[string_to_find]','[string_to_replace]');
>>
>> My real world usage is:
>>
>> UPDATE attachments SET fileloc = REPLACE(fileloc,'2001','2001\');
>>
>> where the backslash is added after the 4-digit year.
>>
>> An example piece of fileloc data looks like "2001DOM-MK008-C.PDF". The
>> column is defined as varchar(50).
>>
>> Any suggestions would be greatly appreciated.

>
> Try doubling up your backslash thus:
> UPDATE attachments SET fileloc = REPLACE(fileloc,'2001','2001\\');
>


Yup, escaping the backslash did the trick. Shame on me for not thinking of
it on my own.

Thanks!


Reply With Quote
  #5 (permalink)  
Old 02-08-2007
Bosconian
 
Posts: n/a
Default Re: replace query

"Sean" <sean.anderson@[nospam]oakleafgroup.biz> wrote in message
news:1170927436.49459@kestrel.skynet.co.uk...
>
> "Bosconian" <nobody@nowhere.com> wrote in message
> news:9q-dneNpi8O2BlfYnZ2dnUVZ_smonZ2d@comcast.com...
>>I been playing with this for awhile, but can't seem to successfully
>>execute a simple replace query with MySQL 4.1.12 via phpMyAdmin 2.7.0-pl2
>>
>> The table only contains around 650 records, yet the query just hangs.
>>
>> I came across this syntax example:
>>
>> update [table_name] set [field_name] =
>> replace([field_name],'[string_to_find]','[string_to_replace]');
>>
>> My real world usage is:
>>
>> UPDATE attachments SET fileloc = REPLACE(fileloc,'2001','2001\');
>>
>> where the backslash is added after the 4-digit year.
>>
>> An example piece of fileloc data looks like "2001DOM-MK008-C.PDF". The
>> column is defined as varchar(50).
>>
>> Any suggestions would be greatly appreciated.
>>
>>

>
> You're getting into a neverending loop
>
> 2001DOM-MK008-C.PDF becomes 2001\DOM-MK008-C.PDF
> 2001\DOM-MK008-C.PDF becomes 2001\\DOM-MK008-C.PDF
> 2001\\DOM-MK008-C.PDF becomes 2001\\\DOM-MK008-C.PDF
>
> Try :
>
> UPDATE attachments SET fileloc = REPLACE(fileloc,'2001','test\');
>
> followed by
>
> UPDATE attachments SET fileloc = REPLACE(fileloc,'test\','2001\');
>
>
>


You might be right about the endless loop although no data ever changed
(probably because the query never finished.) The solution in this case
though was to simply escape the backslash.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 04:38 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0