简体   繁体   中英

MYSQL: Using column name in CONCAT() function gives syntax error 1064

I have this query

UPDATE `fitment_drums` SET `liters` = CONCAT(`liters`,'.0') WHERE `liters` LIKE '_'

Which results in this error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''.0') FROM `fitment_drums` WHERE `liters` LIKE '_'' at line 1

When I substitute an ordinary string, eg. CONCAT ('asdf','.0') it works fine. I've tried using a select statement as an argument, and have also tried using a temporary table:

CREATE TEMPORARY TABLE t1 (SELECT * FROM `fitment_drums` WHERE liters like '_') 
UPDATE `fitment_drums` SET liters = CONCAT(t1.liters,'.0') where t1.id = id

Ok, so I found the "solution". I was running the query in simulation mode, which results in the error posted above. So I backed up the table and executed the query in live mode, and it worked. (for the record, I'm using phpMyAdmin)

Very strange.

Thanks to everyone who tried to help!

Since you revealed that you're using phpMyAdmin, you should know that temporary tables are dropped automatically as a database connection ends.

Each page view in phpMyAdmin is a separate PHP request, and thus a separate database connection.

So if you CREATE TEMPORARY TABLE in phpMyAdmin, then the temp table did not exist anymore by the time you ran your UPDATE .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM