Converting URL to Local File Path in Batch MySQL INSERT Query Using SUBSTRING_INDEX() and CONCAT()

I wanted to quickly take a URL (e.g. http://www.compiledweekly.com/somefolder/somefile.ext) and translate it to the local path (e.g. /home/user/public_html/somefolder/somefile.ext) while inserting multiple records into a new table. My first thought was to select all the records, use PHP to trim off the path, then insert the new record in the new table. There’s a better answer, use SUBSTRING_INDEX() and CONCAT() with a INSERT INTO table SELECT statement.

INSERT INTO new_table
SELECT CONCAT(‘/home/user/public_html/somefolder/’, SUBSTRING_INDEX(s.url, ‘/’, -1)) AS local_path
FROM source_table AS s
WHERE …

It does the job with out having to write a single line of PHP code!

Sun acquires MySQL

If you have not herd, Sun Microsystems is acquiring MySQL. I think this is a great move, especially since Sun has embraced the open source community as strong, if not stronger, than other large companies such as IBM, Yahoo and Google.

Article: http://www.mysql.com/news-and-events/sun-to-acquire-mysql.html

I think the move is a good one for MySQL. With the recent purchase of the InnoDB storage engine by Oracle, there has been some concern that MySQL could end up in the hands of a company that’s best interests do not involve the open source community.

The recent influx of participation in the development of MySQL by Google gives me a lot of hope that MySQL’s future will be a bright one. The next generation storage engine called Falcon hopes to become a replacement for InnoDB and many of the performance tweaks Google has implemented over the years will most likely find their way into the future versions of MySQL.