[MDEV-14901] Order by JSON element is wrong Created: 2018-01-09 Updated: 2018-01-09 Resolved: 2018-01-09 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | JSON |
| Affects Version/s: | None |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Yiftach Kaplan | Assignee: | Sergei Golubchik |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Description |
|
I have a table with a JSON column and I'm trying to sort by a numeric element of the column, but the results order is wrong. For example:
Expected results (results in MySQL 5.7.20):
Actual results (MariaDb 10.2.12):
|
| Comments |
| Comment by Sergei Golubchik [ 2018-01-09 ] | ||||||||||
|
This is expected behavior. JSON_EXTRACT() is a non-standard function that returns either a JSON value or a JSON object. When it returns a value it behaves as a standard JSON_VALUE() function. The standard syntax (SQL:2016, part 2, 6.27 <JSON value function>) is
And the Syntax Rules say
MariaDB does not support <JSON returning clause> yet, so JSON_VALUE() always returns a "character string type", as required by the SQL Standard. That's why the sorting is done by the string comparison rules. According to the SQL Standard, if you want a numeric sorting, you need to say it explicitly. |