Possible JSON subtype regression in json_each/json_tree in 3.45.1?
(1) By Alex Garcia (alexgarciaxyz) on 2024-02-16 21:06:06 [source]
The json_each() and json_tree() table functions used to apply the JSON subtype to the value column if the value was a JSON object/array. For example, the query:
select *, subtype(value) from json_tree('[1,2,3]');
This query uses the subtype() on the value column. I would expect that for the 4 rows that are returned in this query, the subtype(value) column would result in 0 for the 1/2/3 numerical rows, and 74 (JSON subtype flag) for the [1,2,3] array row.
This matches what I see in 3.41.0:
SQLite version 3.41.0 2022-12-27 22:46:49
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .mode box
sqlite> .header on
sqlite> select *, subtype(value) from json_tree('[1,2,3]');
┌─────┬─────────┬─────────┬──────┬────┬────────┬─────────┬──────┬────────────────┐
│ key │ value │ type │ atom │ id │ parent │ fullkey │ path │ subtype(value) │
├─────┼─────────┼─────────┼──────┼────┼────────┼─────────┼──────┼────────────────┤
│ │ [1,2,3] │ array │ │ 0 │ │ $ │ $ │ 74 │
│ 0 │ 1 │ integer │ 1 │ 1 │ 0 │ $[0] │ $ │ 0 │
│ 1 │ 2 │ integer │ 2 │ 2 │ 0 │ $[1] │ $ │ 0 │
│ 2 │ 3 │ integer │ 3 │ 3 │ 0 │ $[2] │ $ │ 0 │
└─────┴─────────┴─────────┴──────┴────┴────────┴─────────┴──────┴────────────────┘
However, in 3.45.1, the subtype for the [1,2,3] row returns 0 instead.
SQLite version 3.45.1 2024-01-30 16:01:20
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .mode box
sqlite> .header on
sqlite> select *, subtype(value) from json_tree('[1,2,3]');
┌─────┬─────────┬─────────┬──────┬────┬────────┬─────────┬──────┬────────────────┐
│ key │ value │ type │ atom │ id │ parent │ fullkey │ path │ subtype(value) │
├─────┼─────────┼─────────┼──────┼────┼────────┼─────────┼──────┼────────────────┤
│ │ [1,2,3] │ array │ │ 0 │ │ $ │ $ │ 0 │
│ 0 │ 1 │ integer │ 1 │ 1 │ 0 │ $[0] │ $ │ 0 │
│ 1 │ 2 │ integer │ 2 │ 3 │ 0 │ $[1] │ $ │ 0 │
│ 2 │ 3 │ integer │ 3 │ 5 │ 0 │ $[2] │ $ │ 0 │
└─────┴─────────┴─────────┴──────┴────┴────────┴─────────┴──────┴────────────────┘
I also see the id column values are different, but that's documented to vary between releases.
So my question: is this expected behavior? I know a lot changed in 3.45 regarding JSON functions + subtype flags, but it would be nice to keep the JSON subtype on these columns when possible.
(2) By Richard Hipp (drh) on 2024-02-17 03:38:10 in reply to 1 [link] [source]
Should be fixed by check-in 1c33c5db2e05019d. Please post a follow-up if you think this fix is incomplete or incorrect.