JSON ordering is not well-ordered.
- Dominant language
- Go
- Stars
- 24.4k
- Forks
- 873
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 108
Description
The MySQL spec requires that JSON objects have an ordering, but this ordering is implementation defined.
Dolt has a comparison function for JSON objects, but it's not well ordered.
```
json> SET @ROCK = JSON_OBJECT('a', 2e0, 'b', 1e0);
json> SET @PAPER = JSON_OBJECT('b', 2e0, 'c', 1e0);
json> SET @SCISSORS = JSON_OBJECT('c', 2e0, 'a', 1e0);
json> SELECT CAST(@ROCK as JSON) < CAST(@PAPER as JSON);
+--------------------------------------------+
| CAST(@ROCK as JSON) < CAST(@PAPER as JSON) |
+--------------------------------------------+
| true |
+--------------------------------------------+
1 row in set (0.00 sec)
json> SELECT CAST(@PAPER as JSON) < CAST(@SCISSORS as JSON);
+------------------------------------------------+
| CAST(@PAPER as JSON) < CAST(@SCISSORS as JSON) |
+------------------------------------------------+
| true |
+------------------------------------------------+
1 row in set (0.00 sec)
json> SELECT CAST(@SCISSORS as JSON) < CAST(@ROCK as JSON);
+-----------------------------------------------+
| CAST(@SCISSORS as JSON) < CAST(@ROCK as JSON) |
+-----------------------------------------------+
| true |
+-----------------------------------------------+
```
(The casts are used here because MySQL doesn't actually permit JSON local variables, so the local variables are strings that need to be re-cast. The values are written as `2e0` to ensure they are parsed as floats, not ints or decimals.)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.