From 4eb6a988977261e7d92319af5f4b0c30741aadf5 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 18 Mar 2016 19:10:44 +0300 Subject: [PATCH] Fix text serialization for NOT operator. Parenthesis needed around NOT, not around its operand. Reported by Pavan Deolasee. --- expected/jsquery.out | 16 +++++++++++----- jsquery_io.c | 2 +- sql/jsquery.sql | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/expected/jsquery.out b/expected/jsquery.out index 24f313b..a550b9a 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -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; @@ -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 ---------- @@ -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; @@ -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; diff --git a/jsquery_io.c b/jsquery_io.c index 89893a3..6e01589 100644 --- a/jsquery_io.c +++ b/jsquery_io.c @@ -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, ')'); diff --git a/sql/jsquery.sql b/sql/jsquery.sql index 6527424..309b790 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -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;