I cannot use json_contains and concat together in MySQL 5.7
Here is an example:
select json_contains(CAST('[1, 2, 3]' AS JSON), CONCAT('\'', 1, '\''));
I got an error:
Data truncation: Invalid JSON text in argument 2 to function json_contains: "Invalid value." at position 0.
However, the following SQL worked fine:
select json_contains(CAST('[1, 2, 3]' AS JSON), '1');
Without upgrading the MySQL version, is there any way to fix the problem?
Related
I use MySQL connector (Python3) and I would Like to upload in a existing Table values of an CSV just one Column. I created a new column in the DB with:
ALTER TABLE myTable ADD `TEST` TEXT;
Now I created a python Query what is the Problem there?
#stvk is my dataframe
for i,row in stvk_u.iterrows():
print(row["datas_of_other_csv"])
cursor.execute("INSERT INTO myTable (TEST) VALUES(%s)",tuple(row["datas_of_other_csv"]))
But I get the error:
Error while connecting to MySQL Not all parameters were used in the SQL statement
Can I do not just insert into a existing table? I do not see what is wrong.
Thanks in advance
The statement requires exactly one parameter, while you provide > 1 parameter.
tuple function splits a string and returns a tuple of characters:
$ python3 -c "print(tuple('foo'))"
('f', 'o', 'o')
Correct would be:
cursor.execute(statement, (row["datas_of_other_csv"],)) # note the comma at the end of tuple
There is Zabbix with PostgreSQL database monitoring. There is one trigger in Zabbix that constantly spam error:
ERROR: function json_object(text[], text[]) does not exist
LINE 11: SELECT json_object(array_agg(name), array_agg(setting)) F...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 190
Found a template in which this trigger is registered. It is standard, I tried to request a line separately in Postgres, as a result the same error.
The request itself:
select json_build_object('extensions',(select array_agg(extname) from (select extname from pg_extension order by extname) as e),'settings', (select json_object(array_agg(name),array_agg(setting)) from (select name,setting from pg_settings where name != 'application_name' order by name) as s));
I ask you to tell what is wrong.
The function json_object(text[], text[]) exists in PostgreSQL (documentation) since version 9.4.
Are you sure you use the version 9.4 or above ? You can check with:
SELECT version();
I'm working with JMeter to load test queries on a mySQL database (memsql server, mySQL syntax). I'm using a gui version of JMeter to create a test plan xml file and then go to another server and run that xml in non-gui mode.
I have two queries running, one that selects and one that inserts. Both queries use parameters taken from a csv file I made with a script.
My SELECT statement works just fine with parameters taken from a csv file but I run into syntax errors with my INSERT statement:
INSERT INTO customer_transactions_current (`column_name1`, ... , `column_name12`)
VALUES ((${r1},${r2},${r3},${r4},${r5},${r6},${r7},${r8},${r9},${r10},${r11},${r12}));
In the section of the query in the gui mode under 'CSV Data Set Config' I choose to delimit the data by ',' and the variable names are r1,..,r12.
Under the query itself I entered the parameter types and again the same names, just as I did for the working SELECT query.
When I run the query I run into a syntax error on the first column (which is of type datetime):
java.sql.SQLSyntaxErrorException: 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 '19:00:00,75400492,936988,56,1115,5,2156,8,2,3,909,3))' at line 2
The dates I'm entering are of the form: '2018-11-2 20:00:00' and in the csv file they are present without apostrophes.
It seems that the syntax error has something to do with the date and in the position where it holds a space. I tried entering the STR_TO_DATE function for that column but kept getting syntax errors.
BUT when I try to take some values from the file and manually run the query it works fine! So my thoughts are that it has something to do JMeter's conversion of spaces before sending out the query.
Is the problem with my configurations of JMeter? Since the query is OK manually.
Add apostrophes to insert and remove unnecessary parenthesis
INSERT INTO customer_transactions_current ('column_name1', ... , 'column_name12')
VALUES ('${r1}','${r2}','${r3}','${r4}','${r5}','${r6}','${r7}','${r8}','${r9}','${r10}','${r11}','${r12}');
If you have date issue see using STR_TO_DATE
I try to run a query on a table and end up with this error:
Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to float.
The query:
SELECT
*, CAST(REPLACE(a.ts_value, ',', '.') AS FLOAT) AS value
FROM
importFromExcel_timeseries a
Is there any hack for a quick allocation of rows that yield this error?
I tried to run put a WHERE isnumeric(a.ts_value) filter, but this does not help
"does not help", does that mean you get the same error? If so, just remove the cast from the select and it should return the rows you're looking for.
i have an delphi application that sends MySQL queries to our server. The following query fails
INSERT INTO `KPT`.`Internalorders`
(`InternalOrderId`, `UserId`, `Text`, `MailSent`,
`Done`, `PartlyDone`, `Ordered`)
VALUES (0, NULL, '- Teststring -- Teststring -', NULL, 1, 1, 1)
with this error message:
MySQL Error Code: (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 ''- Teststring' at line 1
It looks like the string gets wordwrapped internally in the third-party-components i use for database access (MySQLDAC) and forms to
'- Teststring
-- Teststring -'
which would lead to treating the second part as a comment. Because i dont have the possibility to change the third-party tools, i'm hoping that theres is a way to escape double-hyphens.
Is there?
You can solve this using parameters and it will yield you several big advantages:
no problems with strings and quotes (as you found out)
resiliency against SQL injection.
Reusable & fast update queries (just change the parameter value and execute again)
Query is easier to read and maintain.
So your query becomes:
INSERT INTO `KPT`.`Internalorders`
(`InternalOrderId`, `UserId`, `Text`, `MailSent`,
`Done`, `PartlyDone`, `Ordered`)
VALUES (0, NULL, :Text, NULL, 1, 1, 1)
Assign the Text parameter via the Params object or use the ParamByName method on the query object and execute it.