-
-
Notifications
You must be signed in to change notification settings - Fork 632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON_EXTRACT comparison/casting issue #348
Comments
could you post schema creation code for table? ( or just |
also, do are you using |
I'm using CREATE TABLE `table` (
`json` json NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
cold you also help me to populate table? Can you post simple insert queries to match your data? |
INSERT INTO `table` (`json`) VALUES ('[1,2,3,4,5]'); |
The value is always an array of integers. |
works for me: conn.query('SELECT * FROM tttable WHERE JSON_EXTRACT(json, "$[1]") >= ?', [5], (err, rows) => {
console.log(err, rows);
}); prints
|
Weird. Any other info I can provide you? Doesn't work for me. |
I'm using mysql server version 5.7.10. Do you have issues when doing same queries from command line?
|
Works perfectly in the command line. |
CLI seems to be fine:
In the code though, I get this: conn.execute('SELECT 1, JSON_ARRAY(1), JSON_EXTRACT(JSON_ARRAY(1), "$[0]"), JSON_TYPE(JSON_EXTRACT(JSON_ARRAY(1), "$[0]"));', [], ...);
+---+---------------+-------------------------------------+------------------------------------------------+
| 1 | JSON_ARRAY(?) | JSON_EXTRACT(JSON_ARRAY(?), "$[0]") | JSON_TYPE(JSON_EXTRACT(JSON_ARRAY(?), "$[0]")) |
+---+---------------+-------------------------------------+------------------------------------------------+
| 1 | [1] | 1 | INTEGER |
+---+---------------+-------------------------------------+------------------------------------------------+
conn.execute('SELECT ?, JSON_ARRAY(?), JSON_EXTRACT(JSON_ARRAY(?), "$[0]"), JSON_TYPE(JSON_EXTRACT(JSON_ARRAY(?), "$[0]"));', [1, 1, 1, 1], ...);
+-----+---------+-------------------------------------+------------------------------------------------+
| ? | JSON_ARRAY(?) | JSON_EXTRACT(JSON_ARRAY(?), "$[0]") | JSON_TYPE(JSON_EXTRACT(JSON_ARRAY(?), "$[0]")) |
+-----+---------------+-------------------------------------+------------------------------------------------+
| "1" | ["1"] | "1" | STRING |
+-----+---------------+-------------------------------------+------------------------------------------------+ |
thanks for more details! I was doing node-mysql2/lib/packets/execute.js Line 89 in aff0b1c
|
Whenever I use anything besides `Types.DECIMAL` for number type, I get `Error: Incorrect arguments to mysqld_stmt_execute`. Related to: sidorares#348
#353 fixes this. |
Using MySQL 5.7, it seems like calling
JSON_EXTRACT(field, path+)
for an integer from a json array isn't allowing me to compare with an integer.Query:
The value in the
json
field is just a simple[1,2,3,4,5]
.I try executing the query with both a string and integer value. Both result in now results.
If I insert the query into MySQL Workbench, it works fine. If I screw the prepared statement route and just put the integer in the query in place of the
?
, it works fine.They way around it so far is casting the
JSON_EXTRACT
value intoUNSIGNED
for the comparison to work:The text was updated successfully, but these errors were encountered: