1

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
9
  • 2
    Is liters a numeric field ? Commented Nov 9, 2016 at 23:05
  • It's a varchar field. Commented Nov 9, 2016 at 23:08
  • You don't have a semicolon following your CREATE TABLE statement. Commented Nov 9, 2016 at 23:15
  • 1
    @grahamj42 Why would that matter for a syntax error? Why would it matter at all, since MySQL automatically converts numbers to strings when used with CONCAT()? Commented Nov 9, 2016 at 23:53
  • 1
    The error isn't coming from the query you showed. The error message says the query contains FROM `fitment_drums` , but that's not anywhere in that query. Commented Nov 9, 2016 at 23:56

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.