json_array_length after json_remove appears wrong in Fiddle?
(1) By Gary (1codedebugger) on 2023-08-28 00:47:51 [source]
Perhaps I'm doing something wrong and/or this is already known (I'm not up on where to check the log of changes and updates between versions), but it appears that the Fiddle has an issue with json_remove in terms of updating the length. Thank you.
In the CLI
SQLite version 3.42.0 2023-05-16 12:36:15
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .version
SQLite 3.42.0 2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf3alt1
zlib version 1.2.13
gcc-13.1.1 20230429
sqlite> .mode column
sqlite> select json_array_length(json_remove('[1]','$[#-1]'));
json_array_length(json_remove('[1]','$[#-1]'))
----------------------------------------------
0
in SQLite Fiddle
SQLite 3.43.0 2023-08-24 12:36:59 0f80b798b3f4b81a7bb4233c58294edd0f1156f36b6ecf5ab8e83631d468778c
clang-16.0.0 (32-bit)
json_array_length(json_remove('[1]','$[#-1]'))
----------------------------------------------
1
And
select arr, json_array_length(arr)
from
(
select json_remove(json_array(1,2,3),'$[#-1]') as arr
);
arr json_array_length(arr)
----- ----------------------
[1,2] 3
(2) By Richard Hipp (drh) on 2023-08-30 18:33:10 in reply to 1 [link] [source]
Simplified test case:
SELECT json_array_length( json_remove('[1,2,3,4]','$[1]') );
The result is 4 instead of 3. The bug was that when json_array_length() receives its JSON input from the output from json_remove(), it continues to count array entries that removed.
Should now be fixed on trunk and on branch-3.43.