aboutsummaryrefslogtreecommitdiff
path: root/src/json.c
diff options
context:
space:
mode:
authordrh <>2024-05-27 13:24:39 +0000
committerdrh <>2024-05-27 13:24:39 +0000
commitfefe24ddf883a1adce600e0812703cfcc9b20b20 (patch)
treedd83eefcc3c2e975747153c838fdb4c4dc9597ce /src/json.c
parent09f87094bd6d2586b2e8e46f514d4d4e8f235c4e (diff)
downloadsqlite-fefe24ddf883a1adce600e0812703cfcc9b20b20.tar.gz
sqlite-fefe24ddf883a1adce600e0812703cfcc9b20b20.zip
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
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c
index 4db468c92..b30189307 100644
--- a/src/json.c
+++ b/src/json.c
@@ -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) ){