Skip to content

Commit 75380d7

Browse files
committed
Fix any operators with empty arrays and objects.
1 parent 856d8ff commit 75380d7

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

expected/jsquery.out

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,28 +1239,28 @@ select 'a = /* noindex */ 5'::jsquery;
12391239
(1 row)
12401240

12411241
--ALL
1242-
select 'a.*: = 4';
1243-
?column?
1244-
----------
1245-
a.*: = 4
1242+
select 'a.*: = 4'::jsquery;
1243+
jsquery
1244+
------------
1245+
"a".*: = 4
12461246
(1 row)
12471247

1248-
select '%: = 4';
1249-
?column?
1250-
----------
1248+
select '%: = 4'::jsquery;
1249+
jsquery
1250+
---------
12511251
%: = 4
12521252
(1 row)
12531253

1254-
select '#:.i = 4';
1255-
?column?
1256-
----------
1257-
#:.i = 4
1254+
select '#:.i = 4'::jsquery;
1255+
jsquery
1256+
------------
1257+
#:."i" = 4
12581258
(1 row)
12591259

12601260
select '[]' @@ '#: ($ > 1 and $ < 5)'::jsquery;
12611261
?column?
12621262
----------
1263-
f
1263+
t
12641264
(1 row)
12651265

12661266
select '[2,3,4]' @@ '#: ($ > 1 and $ < 5)'::jsquery;
@@ -1289,6 +1289,24 @@ select '[2,3,"x"]' @@ '#: ($ > 1 and $ < 5)'::jsquery;
12891289

12901290
select '{}' @@ '%: ($ > 1 and $ < 5)'::jsquery;
12911291
?column?
1292+
----------
1293+
t
1294+
(1 row)
1295+
1296+
select '{}' @@ '*: ($ is object)'::jsquery;
1297+
?column?
1298+
----------
1299+
t
1300+
(1 row)
1301+
1302+
select '"a"' @@ '*: is string'::jsquery;
1303+
?column?
1304+
----------
1305+
t
1306+
(1 row)
1307+
1308+
select '1' @@ '*: is string'::jsquery;
1309+
?column?
12921310
----------
12931311
f
12941312
(1 row)

jsquery_op.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ recursiveAny(JsQueryItem *jsq, JsonbValue *jb)
9292
static bool
9393
recursiveAll(JsQueryItem *jsq, JsonbValue *jb)
9494
{
95-
bool res = false;
95+
bool res = true;
9696
JsonbIterator *it;
9797
int32 r;
9898
JsonbValue v;
@@ -436,6 +436,9 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb)
436436
jsqGetNext(jsq, &elem);
437437
it = JsonbIteratorInit(jb->val.binary.data);
438438

439+
if (jsq->type == jqiAllArray)
440+
res = true;
441+
439442
while((r = JsonbIteratorNext(&it, &v, true)) != WJB_DONE)
440443
{
441444
if (r == WJB_ELEM)
@@ -451,7 +454,6 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb)
451454
{
452455
if (res == false)
453456
break;
454-
res = true; /* if not executed at least one time */
455457
}
456458
}
457459
}
@@ -468,6 +470,9 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb)
468470
jsqGetNext(jsq, &elem);
469471
it = JsonbIteratorInit(jb->val.binary.data);
470472

473+
if (jsq->type == jqiAllKey)
474+
res = true;
475+
471476
while((r = JsonbIteratorNext(&it, &v, true)) != WJB_DONE)
472477
{
473478
if (r == WJB_VALUE)
@@ -483,7 +488,6 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb)
483488
{
484489
if (res == false)
485490
break;
486-
res = true; /* if not executed at least one time */
487491
}
488492
}
489493
}

sql/jsquery.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,18 @@ select 'a = /*-- noindex */ 5'::jsquery;
255255
select 'a = /* noindex */ 5'::jsquery;
256256

257257
--ALL
258-
select 'a.*: = 4';
259-
select '%: = 4';
260-
select '#:.i = 4';
258+
select 'a.*: = 4'::jsquery;
259+
select '%: = 4'::jsquery;
260+
select '#:.i = 4'::jsquery;
261261
select '[]' @@ '#: ($ > 1 and $ < 5)'::jsquery;
262262
select '[2,3,4]' @@ '#: ($ > 1 and $ < 5)'::jsquery;
263263
select '[2,3,5]' @@ '#: ($ > 1 and $ < 5)'::jsquery;
264264
select '[2,3,5]' @@ '# ($ > 1 and $ < 5)'::jsquery;
265265
select '[2,3,"x"]' @@ '#: ($ > 1 and $ < 5)'::jsquery;
266266
select '{}' @@ '%: ($ > 1 and $ < 5)'::jsquery;
267+
select '{}' @@ '*: ($ is object)'::jsquery;
268+
select '"a"' @@ '*: is string'::jsquery;
269+
select '1' @@ '*: is string'::jsquery;
267270
select '{"a":2,"b":3,"c":4}' @@ '%: ($ > 1 and $ < 5)'::jsquery;
268271
select '{"a":2,"b":3,"c":5}' @@ '%: ($ > 1 and $ < 5)'::jsquery;
269272
select '{"a":2,"b":3,"c":5}' @@ '% ($ > 1 and $ < 5)'::jsquery;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy