Skip to content

Commit 4eb6a98

Browse files
author
Alexander Korotkov
committed
Fix text serialization for NOT operator. Parenthesis needed around NOT, not
around its operand. Reported by Pavan Deolasee.
1 parent 509ca85 commit 4eb6a98

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

expected/jsquery.out

+11-5
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,13 @@ select 'not < 1'::jsquery;
376376
select 'not not < 1'::jsquery;
377377
jsquery
378378
-----------------
379-
NOT ("not" < 1)
379+
(NOT "not" < 1)
380380
(1 row)
381381

382382
select 'not( not < 1)'::jsquery;
383383
jsquery
384384
-----------------
385-
NOT ("not" < 1)
385+
(NOT "not" < 1)
386386
(1 row)
387387

388388
select 'not.x < 1'::jsquery;
@@ -397,6 +397,12 @@ select 'x.not < 1'::jsquery;
397397
"x"."not" < 1
398398
(1 row)
399399

400+
select 'a.%(not x > 0 and not (y < 0 or z = 0))'::jsquery;
401+
jsquery
402+
-----------------------------------------------------
403+
"a".%((NOT "x" > 0) AND (NOT ("y" < 0 OR "z" = 0)))
404+
(1 row)
405+
400406
select 'is < 1'::jsquery;
401407
jsquery
402408
----------
@@ -412,13 +418,13 @@ select 'in < 1'::jsquery;
412418
select 'not is < 1'::jsquery;
413419
jsquery
414420
----------------
415-
NOT ("is" < 1)
421+
(NOT "is" < 1)
416422
(1 row)
417423

418424
select 'not in < 1'::jsquery;
419425
jsquery
420426
----------------
421-
NOT ("in" < 1)
427+
(NOT "in" < 1)
422428
(1 row)
423429

424430
select 'in in (1,2)'::jsquery;
@@ -844,7 +850,7 @@ select 'asd.# = 3'::jsquery & 'zzz = true' | 'xxx.# = zero';
844850
select !'asd.# = 3'::jsquery & 'zzz = true' | !'xxx.# = zero';
845851
?column?
846852
------------------------------------------------------------------
847-
((NOT ("asd".# = 3) AND "zzz" = true) OR NOT ("xxx".# = "zero"))
853+
(((NOT "asd".# = 3) AND "zzz" = true) OR (NOT "xxx".# = "zero"))
848854
(1 row)
849855

850856
select '{"x":[0,1,1,2]}'::jsonb @@ 'x @> [1,0]'::jsquery;

jsquery_io.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ printJsQueryItem(StringInfo buf, JsQueryItem *v, bool inKey, bool printBracketes
315315
appendStringInfoChar(buf, ')');
316316
break;
317317
case jqiNot:
318-
appendBinaryStringInfo(buf, "NOT (", 5);
318+
appendBinaryStringInfo(buf, "(NOT ", 5);
319319
jsqGetArg(v, &elem);
320320
printJsQueryItem(buf, &elem, false, true);
321321
appendStringInfoChar(buf, ')');

sql/jsquery.sql

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ select 'not not < 1'::jsquery;
7575
select 'not( not < 1)'::jsquery;
7676
select 'not.x < 1'::jsquery;
7777
select 'x.not < 1'::jsquery;
78+
select 'a.%(not x > 0 and not (y < 0 or z = 0))'::jsquery;
7879

7980
select 'is < 1'::jsquery;
8081
select 'in < 1'::jsquery;

0 commit comments

Comments
 (0)