For compatibility with PostgreSQL, when right-hand side of the ->> operator

is negative, it should index from the right side of the JSON array on the
left-hand side.

FossilOrigin-Name: 82365a45b96536c1146a384e5d3efce80a6ec469a54713c7f40bf15eb834b5fd
This commit is contained in:
drh 2024-05-27 13:24:39 +00:00
parent 09f87094bd
commit fefe24ddf8
3 changed files with 14 additions and 8 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\spossible\sbuffer\soverwrite\sin\sthe\s".import"\scommand.\s[forum:/forumpost/0c447f0548|forum\spost\s0c447f0548].
D 2024-05-27T11:35:05.208
C For\scompatibility\swith\sPostgreSQL,\swhen\sright-hand\sside\sof\sthe\s->>\soperator\nis\snegative,\sit\sshould\sindex\sfrom\sthe\sright\sside\sof\sthe\sJSON\sarray\son\sthe\nleft-hand\sside.
D 2024-05-27T13:24:39.941
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -715,7 +715,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 4bd7c7e54a1062dcd0214b7a6296f7194eb10fb14d3ddca1ed20b01c2a86a18c
F src/json.c bf1b51e32158b3d01d96a878d3dba8d2e633a7e5bf2534d4617f89de8a6b9a91
F src/json.c 06cd3a8df28a1bf29e3ee731fc04318aad58bf3fe48f82c8cf98038a98c3bd73
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36
F src/main.c 8a59d297ec77e6b78550433bfccb95a1b26f2fb69aaaf233206e21579a1cfcc1
@ -2193,8 +2193,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 857f6d530949221d154b5120ecc2aa906418bec6f69d1c13197a432ba3cad8eb
R 208aed0e15e5a9e1542642ed290f707d
U dan
Z dedd3aceb57544d244ea5c9933280761
P 0fd958fa9b56a8ef254127e29800ca2a267590e86edf739bd339239b25a5da6e
R 36f341dbd61e9f589a60e0c721370ef1
U drh
Z 1b11798b82660ce66802b4d7d9bc3cf5
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
0fd958fa9b56a8ef254127e29800ca2a267590e86edf739bd339239b25a5da6e
82365a45b96536c1146a384e5d3efce80a6ec469a54713c7f40bf15eb834b5fd

View File

@ -3857,10 +3857,16 @@ static void jsonExtractFunc(
** NUMBER ==> $[NUMBER] // PG compatible
** LABEL ==> $.LABEL // PG compatible
** [NUMBER] ==> $[NUMBER] // Not PG. Purely for convenience
**
** Updated 2024-05-27: If the NUMBER is negative, then PG counts from
** the write of the array. Hence for negative NUMBER:
**
** NUMBER ==> $[#NUMBER] // PG compatible
*/
jsonStringInit(&jx, ctx);
if( sqlite3_value_type(argv[i])==SQLITE_INTEGER ){
jsonAppendRawNZ(&jx, "[", 1);
if( zPath[0]=='-' ) jsonAppendRawNZ(&jx,"#",1);
jsonAppendRaw(&jx, zPath, nPath);
jsonAppendRawNZ(&jx, "]", 2);
}else if( jsonAllAlphanum(zPath, nPath) ){