Skip to content

Commit

Permalink
Fix text serialization for NOT operator. Parenthesis needed around NO…
Browse files Browse the repository at this point in the history
…T, not

around its operand.

Reported by Pavan Deolasee.
  • Loading branch information
Alexander Korotkov committed Mar 18, 2016
1 parent 509ca85 commit 4eb6a98
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
16 changes: 11 additions & 5 deletions expected/jsquery.out
Expand Up @@ -376,13 +376,13 @@ select 'not < 1'::jsquery;
select 'not not < 1'::jsquery;
jsquery
-----------------
NOT ("not" < 1)
(NOT "not" < 1)
(1 row)

select 'not( not < 1)'::jsquery;
jsquery
-----------------
NOT ("not" < 1)
(NOT "not" < 1)
(1 row)

select 'not.x < 1'::jsquery;
Expand All @@ -397,6 +397,12 @@ select 'x.not < 1'::jsquery;
"x"."not" < 1
(1 row)

select 'a.%(not x > 0 and not (y < 0 or z = 0))'::jsquery;
jsquery
-----------------------------------------------------
"a".%((NOT "x" > 0) AND (NOT ("y" < 0 OR "z" = 0)))
(1 row)

select 'is < 1'::jsquery;
jsquery
----------
Expand All @@ -412,13 +418,13 @@ select 'in < 1'::jsquery;
select 'not is < 1'::jsquery;
jsquery
----------------
NOT ("is" < 1)
(NOT "is" < 1)
(1 row)

select 'not in < 1'::jsquery;
jsquery
----------------
NOT ("in" < 1)
(NOT "in" < 1)
(1 row)

select 'in in (1,2)'::jsquery;
Expand Down Expand Up @@ -844,7 +850,7 @@ select 'asd.# = 3'::jsquery & 'zzz = true' | 'xxx.# = zero';
select !'asd.# = 3'::jsquery & 'zzz = true' | !'xxx.# = zero';
?column?
------------------------------------------------------------------
((NOT ("asd".# = 3) AND "zzz" = true) OR NOT ("xxx".# = "zero"))
(((NOT "asd".# = 3) AND "zzz" = true) OR (NOT "xxx".# = "zero"))
(1 row)

select '{"x":[0,1,1,2]}'::jsonb @@ 'x @> [1,0]'::jsquery;
Expand Down
2 changes: 1 addition & 1 deletion jsquery_io.c
Expand Up @@ -315,7 +315,7 @@ printJsQueryItem(StringInfo buf, JsQueryItem *v, bool inKey, bool printBracketes
appendStringInfoChar(buf, ')');
break;
case jqiNot:
appendBinaryStringInfo(buf, "NOT (", 5);
appendBinaryStringInfo(buf, "(NOT ", 5);
jsqGetArg(v, &elem);
printJsQueryItem(buf, &elem, false, true);
appendStringInfoChar(buf, ')');
Expand Down
1 change: 1 addition & 0 deletions sql/jsquery.sql
Expand Up @@ -75,6 +75,7 @@ select 'not not < 1'::jsquery;
select 'not( not < 1)'::jsquery;
select 'not.x < 1'::jsquery;
select 'x.not < 1'::jsquery;
select 'a.%(not x > 0 and not (y < 0 or z = 0))'::jsquery;

select 'is < 1'::jsquery;
select 'in < 1'::jsquery;
Expand Down

0 comments on commit 4eb6a98

Please sign in to comment.