diff options
author | drh <> | 2023-10-05 15:02:00 +0000 |
---|---|---|
committer | drh <> | 2023-10-05 15:02:00 +0000 |
commit | 9061e22a05f7b0037a9121a8f58f26e37ae8c2f0 (patch) | |
tree | 5d4d2fd424caec9e2d358dba6b2ca22e51b26808 /src/json.c | |
parent | 0f921e2bac679f560049e4d3d660710a42671f5f (diff) | |
download | sqlite-9061e22a05f7b0037a9121a8f58f26e37ae8c2f0.tar.gz sqlite-9061e22a05f7b0037a9121a8f58f26e37ae8c2f0.zip |
Allow the PG-style syntax for the PATH operand on the right-hand side of
the ->> and -> operators.
FossilOrigin-Name: bae5071b0834aa3b7fd4bd871f863e1b148c6558989c8f6cdd02dc4da4770953
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/json.c b/src/json.c index 955c35377..3307db0ba 100644 --- a/src/json.c +++ b/src/json.c @@ -3990,12 +3990,38 @@ static void jsonExtractFromBlob( u32 i; JsonParse px; if( zPath==0 ) return; - if( zPath[0]=='$' ) zPath++; memset(&px, 0, sizeof(px)); px.nBlob = sqlite3_value_bytes(pJson); px.aBlob = (u8*)sqlite3_value_blob(pJson); if( px.aBlob==0 ) return; - i = jsonLookupBlobStep(&px, 0, zPath, &zErr); + if( zPath[0]=='$' ){ + zPath++; + i = jsonLookupBlobStep(&px, 0, zPath, &zErr); + }else if( (flags & JSON_ABPATH) ){ + /* The -> and ->> operators accept abbreviated PATH arguments. This + ** is mostly for compatibility with PostgreSQL, but also for + ** convenience. + ** + ** NUMBER ==> $[NUMBER] // PG compatible + ** LABEL ==> $.LABEL // PG compatible + ** [NUMBER] ==> $[NUMBER] // Not PG. Purely for convenience + */ + JsonString jx; + jsonStringInit(&jx, ctx); + if( sqlite3Isdigit(zPath[0]) ){ + jsonAppendRawNZ(&jx, "[", 1); + jsonAppendRaw(&jx, zPath, (int)strlen(zPath)); + jsonAppendRawNZ(&jx, "]", 2); + zPath = jx.zBuf; + }else if( zPath[0]!='[' ){ + jsonAppendRawNZ(&jx, ".", 1); + jsonAppendRaw(&jx, zPath, (int)strlen(zPath)); + jsonAppendChar(&jx, 0); + zPath = jx.zBuf; + } + i = jsonLookupBlobStep(&px, 0, zPath, &zErr); + jsonStringReset(&jx); + } if( i<px.nBlob ){ jsonReturnFromBlob(&px, i, ctx); }else if( i==JSON_BLOB_NOTFOUND ){ |