Truncated incorrect DOUBLE value when updating mysql column - mysql

when trying to update my mysql database-column with following sql command
UPDATE db.vendor_horses SET image='{"images":["' + image + '"]}';
I get following error:
UPDATE db.vendor_horses SET image='{"images":["' + image + '"]}' Error Code: 1292. Truncated incorrect DOUBLE value: '{"images":["' 0.00028 sec
I can't figure out what's wrong..

in mysql + is not valid concatenation sign. (MySQL concatenation operator)
you should use CONCAT function.
UPDATE db.vendor_horses SET image= CONCAT('{"images":["', image, '"]}';

Related

Error: '1054 (42S22): Unknown column 'Jo' in 'field list''

I'm attempting to execute a simple query that inserts two names, "self.player1", and "self.player2" as VARCHAR datatypes into a table on a MySQL server version 8.0.31. When I call a custom-built function called "execute_query()" provided below, I receive the following error in my terminal:
Error: '1054 (42S22): Unknown column 'Jo' in 'field list''
Function Definition of "execute_query()":
def execute_query(self, query):
''' This function takes SQL queries stored
in Python as strings and passes them
to the "cursor.execute()" method to
execute them on the server'''
cursor = self.connection.cursor()
try:
cursor.execute(query)
self.connection.commit() # Implements commands detailed in SQL queries
print(query + "Query successful")
except Error as err:
print(f"Error: '{err}'")
The names of the attributes are "player_1" and "player_2", and the values to be inserted are assigned to variable names "self.player1", and "self.player2" as shown below.
query = "USE " + self.db_obj.db_name + ";"
self.db_obj.execute_query(query)
query = "INSERT INTO `match`(player_1, player_2) VALUES (" + self.player1 + "," + self.player2 + ");"
It is important to mention that the issue is not with the "execute_query()" function as I have been able to successfully execute other queries. Additionally, I have run through numerous other similar issues on this discussion forum and have tried dropping triggers, changing secure file priviliges, and hardcoding the value of my entries into the query as opposed to concatenating the values to other strings to produce the resultant query, and have not had any luck.
The design of the table, match is provided below (Note: I was not able to write out the contents of this query to a text file using the following command:
SELECT * FROM `match`
INTO OUTFILE "test.txt";
as I received this error:
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
The query that I used to generated the table in the image below is:
DESCRIBE `match`;
Your error says : Error: '1054 (42S22): Unknown column 'Jo' in 'field list''.
The word 'Jo' in the error is not a field name but a player name. You need to modify your query to :
query = "INSERT INTO `match`(player_1, player_2) VALUES ('" + self.player1 + "','" + self.player2 + "');"
Since string values need to be between single quotes.

MYSQL - insert a variable into a string

I have created 2 variables
SET #SG_Positivity = 1600000000000027;
SET #SG_Relationship = 1700000000000027;
I want to use these inside of a string in my INSERT
INSERT INTO `core`.`card_config` (`version`,`scoring_model_id`,`locale_id`,`card_type`,`config`,`company_interview_id`)
VALUES('1',#ScoreModelID,'1','TTC','{"'+#SG_Positivity+'":{"summary":Tailored, personalized care"'+#SG_Relationship+'":{"summary":Ability to move others to action',NULL);
When executing the statement, I get the following error
Warning Code : 1292 Truncated incorrect DOUBLE value: '{"'
INSERT INTO core.card_config (version,scoring_model_id,locale_id,card_type,config,company_interview_id)
VALUES('1',#ScoreModelID,'1','TTC','{""'+#SG_Positivity+'''":{"''summary":Tailored, personalized care"'+#SG_Relationship+'":{"summary":Ability to move others to action"',
NULL);
Try above solution if nothing work then refer refer this for more information

MySQL Syntax error in the update statement, NodeJS(MySQL2) module

I am using Node.JS along with the mysql2 module. It's basically like when I try to update a column with a JSON stingified data, I get the following error:
{ Error: You have an error in your SQL syntax; check the manual that corresponds
to your MariaDB server version for the right syntax to use near '"1050":1}WHERE
`user` = ?' at line 1
The stingified JSON data:
{"1050":1}
The query:
var sql = 'UPDATE `users` SET `furniture` = ' + 'concat(furniture,' + JSON.stringify(self.furniture) + ')' + 'WHERE `user` = ?';
self.furniture is related to something else, but I can assure you that self.furniture is returning that JSON data thus I get the mysql syntax error.
sqlMessage: 'You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near \'"1050":
Issue is resolved using backticks along with single quotes.
var sql = 'UPDATE `users` SET `furniture` = ' + `concat(furniture, '${lol}')` + 'WHERE `user` = ?';
var lol = JSON.stringify(self.furniture)
Your query line says in part
...ingify(self.furniture) + ')' + 'WHERE `us...
It should have an extra space after the close parenthesis.
...ingify(self.furniture) + ') ' + 'WHERE `us...
Here's the thing about MySQL syntax errors: the message shows the erroneous query starting with the first character MySQL does not understand. A good way to troubleshoot this kind of thing is to use console.log() to output the entire query string, then look at it carefully. You will usually find something obvious wrong.

Error trying to add .jpg at the end of filename in mysql

I have an attribute in a table that goes 1, 2, 3, 4, 5, ..... Right now, I'm trying to add .jpg to the file name. That is, it should be 1.jpg, 2.jpg, 3.jpg, 4.jpg,....
I tried using that command:
UPDATE tbl_items set filename = CAST(itemID AS char(10)) + '.jpg'
I'm getting this error
1292 Truncated incorrect DOUBLE value: '.jpg'
Can anyone tell me what is wrong?
The plus operator isn't valid in MySQL for string concatenation. Instead, try using CONCAT():
UPDATE tbl_items
SET filename = CONCAT(CAST(itemID AS CHAR(10)), '.jpg')
Your current error is probably arising because MySQL assumes you are trying to do arithmetic with either side of the plus operator.

SQL DATETIME in create table causes parsing error

When attempting to run this query in Node.JS/Express using MySQL, I get an error.
Without the line "created DATETIME,\n" the code works perfectly. When including that line, or any variation of it (such as trying to attempt to put a default date of the current time), it also says the exact same error.
"You have an error in your SQL syntax; check the ... (redacted) ... for the right syntax to use near '' at line 4"
var create_elements =
"CREATE TABLE elements(\n" +
"id INT NOT NULL AUTO_INCREMENT,\n" +
"googleID VARCHAR(60),\n" +
"created DATETIME,\n"
"title VARCHAR(300),\n" +
"body TEXT,\n" +
"type ENUM('blog', 'issue'),\n" +
"PRIMARY KEY (id)\n" +
");";
There is no plus sign after your new string snippet containing the DATETIME line, so the resulting string does not contain the remaining elements or closing parenthesis and is syntactically invalid.