From 41725de3a891737806e57e62ddc6d9f7c520613c Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 26 Jan 2018 12:59:48 +0300 Subject: [PATCH 01/53] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a019b4..d96ad69 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ and supports PostgreSQL 9.4+. Regards ------- -Development is sponsored by [Wargaming.net](http://wargaming.net). +Development was sponsored by [Wargaming.net](http://wargaming.net). Installation ------------ From 72552ecb8bc8ea066e00ed9b6cfff9dbde990061 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Mon, 29 Jan 2018 13:42:39 +0300 Subject: [PATCH 02/53] set standard_conforming_strings for tests to prevent test failing --- expected/jsquery.out | 1 + sql/jsquery.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/expected/jsquery.out b/expected/jsquery.out index afb988d..e747d9a 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -1,5 +1,6 @@ CREATE EXTENSION jsquery; set escape_string_warning=off; +set standard_conforming_strings=on; CREATE TABLE test_jsquery (v jsonb); \copy test_jsquery from 'data/test_jsquery.data' select 'asd.zzz = 13'::jsquery; diff --git a/sql/jsquery.sql b/sql/jsquery.sql index fb5319a..d264955 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -1,6 +1,7 @@ CREATE EXTENSION jsquery; set escape_string_warning=off; +set standard_conforming_strings=on; CREATE TABLE test_jsquery (v jsonb); From 3342d8ac847fcedb0e8a5f6d19ecb4c8d94d22dd Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Thu, 1 Feb 2018 21:27:18 +0300 Subject: [PATCH 03/53] filter works --- expected/jsquery.out | 169 +++++++++++++++++++++++++++++++ jsquery--1.0.sql | 11 +++ jsquery.h | 8 +- jsquery_gram.y | 57 ++++++----- jsquery_io.c | 16 ++- jsquery_op.c | 229 +++++++++++++++++++++++++++++++++++-------- jsquery_scan.l | 4 +- jsquery_support.c | 3 + sql/jsquery.sql | 30 ++++++ 9 files changed, 454 insertions(+), 73 deletions(-) diff --git a/expected/jsquery.out b/expected/jsquery.out index e747d9a..ccab908 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -1446,6 +1446,175 @@ select '{"a":[1,2]}' @@ '@# = 1'::jsquery; t (1 row) +--filter +select '?( not b>0). x'::jsquery; + jsquery +------------------------ + ?((NOT "b" > 0)) ."x" +(1 row) + +select 'a.?(b>0 and x= 0 ) .c'::jsquery; + jsquery +----------------------------------- + "a" ?(("b" > 0 AND "x" = 0)) ."c" +(1 row) + +select 'a.$. ?(b>0 and x= 0 ) . c.k'::jsquery; + jsquery +----------------------------------------- + "a".$ ?(("b" > 0 AND "x" = 0)) ."c"."k" +(1 row) + +select 'a.$.? (b>0 and x.*= 0 ).c.k'::jsquery; + jsquery +------------------------------------------- + "a".$ ?(("b" > 0 AND "x".* = 0)) ."c"."k" +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a < 0) (b=20)'; + ?column? +---------- + f +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 0) (b=20)'; + ?column? +---------- + t +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 1) (b=20)'; + ?column? +---------- + t +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 2) (b=20)'; + ?column? +---------- + f +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 3) (b=20)'; + ?column? +---------- + f +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#.a'; + ?column? +---------- + [1, 2] +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#. ?(a > 1). b'; + ?column? +---------- + [20] +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '# . ?(a > 1)'; + ?column? +---------------------------------------- + [{"a": 2, "b": 20}, {"a": 3, "b": 30}] +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '%'; + ?column? +---------- + +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '%'; + ?column? +----------- + [1, 2, 3] +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 )'; + ?column? +---------- + [3] +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 ).$'; + ?column? +---------- + [3] +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( % > 2 )'; + ?column? +---------------------------- + [{"a": 1, "b": 2, "c": 3}] +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 0 )'; + ?column? +---------------------------- + [{"a": 1, "b": 2, "c": 3}] +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 2 )'; + ?column? +---------- + +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '#'; + ?column? +----------------------------------------------------------- + [{"a": 1, "b": 10}, {"a": 2, "b": 20}, {"a": 3, "b": 30}] +(1 row) + +select '[1,2,3]'::jsonb ~~ '#'; + ?column? +----------- + [1, 2, 3] +(1 row) + +select '[1,2,3]'::jsonb ~~ '#. ?($ > 2)'; + ?column? +---------- + [3] +(1 row) + +select '[1,2,3]'::jsonb ~~ '#. ?($ > 2).$'; + ?column? +---------- + [3] +(1 row) + +select '[1,2,3]'::jsonb ~~ ' ?(#.$ > 2).$'; + ?column? +------------- + [[1, 2, 3]] +(1 row) + +select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 2).$'; + ?column? +---------- + +(1 row) + +select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 0).$'; + ?column? +------------- + [[1, 2, 3]] +(1 row) + +select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '*.?(c >0)'; + ?column? +------------ + [{"c": 1}] +(1 row) + +select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '?(*.c >0)'; + ?column? +-------------------------- + [{"a": {"b": {"c": 1}}}] +(1 row) + --ALL select 'a.*: = 4'::jsquery; jsquery diff --git a/jsquery--1.0.sql b/jsquery--1.0.sql index 3bf1d9b..bec1279 100644 --- a/jsquery--1.0.sql +++ b/jsquery--1.0.sql @@ -48,6 +48,17 @@ CREATE OPERATOR @@ ( JOIN = contjoinsel ); +CREATE FUNCTION json_jsquery_filter(jsonb, jsquery) + RETURNS jsonb + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +CREATE OPERATOR ~~ ( + LEFTARG = jsonb, + RIGHTARG = jsquery, + PROCEDURE = json_jsquery_filter +); + CREATE FUNCTION jsquery_join_and(jsquery, jsquery) RETURNS jsquery AS 'MODULE_PATHNAME' diff --git a/jsquery.h b/jsquery.h index d98dd6c..fbfc5c5 100644 --- a/jsquery.h +++ b/jsquery.h @@ -57,12 +57,13 @@ typedef enum JsQueryItemType { jqiLength, jqiIn, jqiIs, - jqiIndexArray + jqiIndexArray, + jqiFilter } JsQueryItemType; /* * JsQueryHint is stored in the same byte as JsQueryItemType so - * JsQueryItemType should not use two high bits + * JsQueryItemType should not use three high bits */ typedef enum JsQueryHint { jsqIndexDefault = 0x00, @@ -84,7 +85,7 @@ typedef enum JsQueryHint { typedef struct JsQueryItem { JsQueryItemType type; JsQueryHint hint; - int32 nextPos; + uint32 nextPos; char *base; union { @@ -135,6 +136,7 @@ struct JsQueryParseItem { JsQueryItemType type; JsQueryHint hint; JsQueryParseItem *next; /* next in path */ + bool filter; union { struct { diff --git a/jsquery_gram.y b/jsquery_gram.y index 7db9a2d..4d1c28a 100644 --- a/jsquery_gram.y +++ b/jsquery_gram.y @@ -1,13 +1,13 @@ /*------------------------------------------------------------------------- * * jsquery_gram.y - * Grammar definitions for jsquery datatype + * Grammar definitions for jsquery datatype * * Copyright (c) 2014, PostgreSQL Global Development Group * Author: Teodor Sigaev * * IDENTIFICATION - * contrib/jsquery/jsquery_gram.y + * contrib/jsquery/jsquery_gram.y * *------------------------------------------------------------------------- */ @@ -43,8 +43,8 @@ fprintf_to_ereport(const char *fmt, const char *msg) /* struct string is shared between scan and gram */ typedef struct string { - char *val; - int len; + char *val; + int len; int total; } string; #include @@ -188,6 +188,9 @@ makeItemList(List *list) { head = end = (JsQueryParseItem*)linitial(list); + while(end->next) + end = end->next; + foreach(cell, list) { JsQueryParseItem *c = (JsQueryParseItem*)lfirst(cell); @@ -197,6 +200,9 @@ makeItemList(List *list) { end->next = c; end = c; + + while(end->next) + end = end->next; } return head; @@ -212,7 +218,7 @@ makeItemList(List *list) { %parse-param {JsQueryParseItem **result} %union { - string str; + string str; List *elems; /* list of JsQueryParseItem */ JsQueryParseItem *value; @@ -225,25 +231,26 @@ makeItemList(List *list) { %token STRING_P NUMERIC_P INT_P -%type result scalar_value +%type result scalar_value %type path value_list -%type key key_any right_expr expr array numeric +%type key key_any right_expr expr array numeric %token HINT_P -%left OR_P -%left AND_P -%right NOT_P -%nonassoc IN_P IS_P +%left OR_P +%left AND_P +%right NOT_P +%nonassoc IN_P IS_P %nonassoc '(' ')' /* Grammar follows */ %% -result: - expr { *result = $1; } +result: + expr { *result = $1; } + | path { *result = makeItemList($1); } | /* EMPTY */ { *result = NULL; } ; @@ -271,8 +278,8 @@ scalar_value: ; value_list: - scalar_value { $$ = lappend(NIL, $1); } - | value_list ',' scalar_value { $$ = lappend($1, $3); } + scalar_value { $$ = lappend(NIL, $1); } + | value_list ',' scalar_value { $$ = lappend($1, $3); } ; numeric: @@ -289,20 +296,20 @@ right_expr: | '>' numeric { $$ = makeItemUnary(jqiGreater, $2); } | '<' '=' numeric { $$ = makeItemUnary(jqiLessOrEqual, $3); } | '>' '=' numeric { $$ = makeItemUnary(jqiGreaterOrEqual, $3); } - | '@' '>' array { $$ = makeItemUnary(jqiContains, $3); } - | '<' '@' array { $$ = makeItemUnary(jqiContained, $3); } + | '@' '>' array { $$ = makeItemUnary(jqiContains, $3); } + | '<' '@' array { $$ = makeItemUnary(jqiContained, $3); } | '&' '&' array { $$ = makeItemUnary(jqiOverlap, $3); } - | IS_P ARRAY_T { $$ = makeItemIs(jbvArray); } - | IS_P NUMERIC_T { $$ = makeItemIs(jbvNumeric); } - | IS_P OBJECT_T { $$ = makeItemIs(jbvObject); } - | IS_P STRING_T { $$ = makeItemIs(jbvString); } - | IS_P BOOLEAN_T { $$ = makeItemIs(jbvBool); } + | IS_P ARRAY_T { $$ = makeItemIs(jbvArray); } + | IS_P NUMERIC_T { $$ = makeItemIs(jbvNumeric); } + | IS_P OBJECT_T { $$ = makeItemIs(jbvObject); } + | IS_P STRING_T { $$ = makeItemIs(jbvString); } + | IS_P BOOLEAN_T { $$ = makeItemIs(jbvBool); } ; expr: path right_expr { $$ = makeItemList(lappend($1, $2)); } | path HINT_P right_expr { $3->hint = $2; $$ = makeItemList(lappend($1, $3)); } - | NOT_P expr { $$ = makeItemUnary(jqiNot, $2); } + | NOT_P expr { $$ = makeItemUnary(jqiNot, $2); } /* * In next two lines NOT_P is a path actually, not a an * logical expression. @@ -346,15 +353,17 @@ key: ; /* - * NOT keyword needs separate processing + * NOT keyword needs separate processing */ key_any: key { $$ = $$; } + | '?' '(' expr ')' { $$ = makeItemUnary(jqiFilter, $3); } | NOT_P { $$ = makeItemKey(&$1); } ; path: key { $$ = lappend(NIL, $1); } + | '?' '(' expr ')' { $$ = lappend(NIL, makeItemUnary(jqiFilter, $3)); } | path '.' key_any { $$ = lappend($1, $3); } | NOT_P '.' key_any { $$ = lappend(lappend(NIL, makeItemKey(&$1)), $3); } ; diff --git a/jsquery_io.c b/jsquery_io.c index a295244..5a7c458 100644 --- a/jsquery_io.c +++ b/jsquery_io.c @@ -1,13 +1,13 @@ /*------------------------------------------------------------------------- * * jsquery_io.c - * I/O functions for jsquery datatype + * I/O functions for jsquery datatype * * Copyright (c) 2014, PostgreSQL Global Development Group * Author: Teodor Sigaev * * IDENTIFICATION - * contrib/jsquery/jsquery_io.c + * contrib/jsquery/jsquery_io.c * *------------------------------------------------------------------------- */ @@ -103,6 +103,7 @@ flattenJsQueryParseItem(StringInfo buf, JsQueryParseItem *item, bool onlyCurrent case jqiContained: case jqiOverlap: case jqiNot: + case jqiFilter: { int32 arg; @@ -154,7 +155,7 @@ jsquery_in(PG_FUNCTION_ARGS) StringInfoData buf; initStringInfo(&buf); - enlargeStringInfo(&buf, 4 * len /* estimation */); + enlargeStringInfo(&buf, 4 * len /* estimation */); appendStringInfoSpaces(&buf, VARHDRSZ); @@ -321,7 +322,8 @@ printJsQueryItem(StringInfo buf, JsQueryItem *v, bool inKey, bool printBracketes appendStringInfoChar(buf, ')'); break; case jqiNot: - appendBinaryStringInfo(buf, "(NOT ", 5); + appendStringInfoChar(buf, '('); + appendBinaryStringInfo(buf, "NOT ", 4); jsqGetArg(v, &elem); printJsQueryItem(buf, &elem, false, true); appendStringInfoChar(buf, ')'); @@ -375,6 +377,12 @@ printJsQueryItem(StringInfo buf, JsQueryItem *v, bool inKey, bool printBracketes appendStringInfoChar(buf, '.'); appendStringInfo(buf, "#%u", v->arrayIndex); break; + case jqiFilter: + appendBinaryStringInfo(buf, " ?(", 3); + jsqGetArg(v, &elem); + printJsQueryItem(buf, &elem, false, false); + appendBinaryStringInfo(buf, ") ", 2); + break; default: elog(ERROR, "Unknown JsQueryItem type: %d", v->type); } diff --git a/jsquery_op.c b/jsquery_op.c index 426257f..db2ca57 100644 --- a/jsquery_op.c +++ b/jsquery_op.c @@ -1,13 +1,13 @@ /*------------------------------------------------------------------------- * * jsquery_op.c - * Functions and operations over jsquery/jsonb datatypes + * Functions and operations over jsquery/jsonb datatypes * * Copyright (c) 2014, PostgreSQL Global Development Group * Author: Teodor Sigaev * * IDENTIFICATION - * contrib/jsquery/jsquery_op.c + * contrib/jsquery/jsquery_op.c * *------------------------------------------------------------------------- */ @@ -29,7 +29,27 @@ #include "jsquery.h" -static bool recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg); +typedef struct ResultAccum { + StringInfo buf; + bool missAppend; + JsonbParseState *jbArrayState; +} ResultAccum; + + +static bool recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg, + ResultAccum *ra); + +static void +appendResult(ResultAccum *ra, JsonbValue *jb) +{ + if (ra == NULL || ra->missAppend == true) + return; + + if (ra->jbArrayState == NULL) + pushJsonbValue(&ra->jbArrayState, WJB_BEGIN_ARRAY, NULL); + + pushJsonbValue(&ra->jbArrayState, WJB_ELEM, jb); +} static int compareNumeric(Numeric a, Numeric b) @@ -67,7 +87,7 @@ JsonbType(JsonbValue *jb) } static bool -recursiveAny(JsQueryItem *jsq, JsonbValue *jb) +recursiveAny(JsQueryItem *jsq, JsonbValue *jb, ResultAccum *ra) { bool res = false; JsonbIterator *it; @@ -88,10 +108,14 @@ recursiveAny(JsQueryItem *jsq, JsonbValue *jb) if (r == WJB_VALUE || r == WJB_ELEM) { - res = recursiveExecute(jsq, &v, NULL); + /* + * we don't need actually store result, we may need to store whole + * object/array + */ + res = recursiveExecute(jsq, &v, NULL, ra); if (res == false && v.type == jbvBinary) - res = recursiveAny(jsq, &v); + res = recursiveAny(jsq, &v, ra); } } @@ -99,7 +123,7 @@ recursiveAny(JsQueryItem *jsq, JsonbValue *jb) } static bool -recursiveAll(JsQueryItem *jsq, JsonbValue *jb) +recursiveAll(JsQueryItem *jsq, JsonbValue *jb, ResultAccum *ra) { bool res = true; JsonbIterator *it; @@ -120,10 +144,14 @@ recursiveAll(JsQueryItem *jsq, JsonbValue *jb) if (r == WJB_VALUE || r == WJB_ELEM) { - if ((res = recursiveExecute(jsq, &v, NULL)) == true) + /* + * we don't need actually store result, we may need to store whole + * object/array + */ + if ((res = recursiveExecute(jsq, &v, NULL, ra)) == true) { if (v.type == jbvBinary) - res = recursiveAll(jsq, &v); + res = recursiveAll(jsq, &v, ra); } if (res == false) @@ -397,7 +425,8 @@ executeExpr(JsQueryItem *jsq, int32 op, JsonbValue *jb, JsQueryItem *jsqLeftArg) } static bool -recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) +recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg, + ResultAccum *ra) { JsQueryItem elem; bool res = false; @@ -407,25 +436,25 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) switch(jsq->type) { case jqiAnd: jsqGetLeftArg(jsq, &elem); - res = recursiveExecute(&elem, jb, jsqLeftArg); + res = recursiveExecute(&elem, jb, jsqLeftArg, ra); if (res == true) { jsqGetRightArg(jsq, &elem); - res = recursiveExecute(&elem, jb, jsqLeftArg); + res = recursiveExecute(&elem, jb, jsqLeftArg, ra); } break; case jqiOr: jsqGetLeftArg(jsq, &elem); - res = recursiveExecute(&elem, jb, jsqLeftArg); + res = recursiveExecute(&elem, jb, jsqLeftArg, ra); if (res == false) { jsqGetRightArg(jsq, &elem); - res = recursiveExecute(&elem, jb, jsqLeftArg); + res = recursiveExecute(&elem, jb, jsqLeftArg, ra); } break; case jqiNot: jsqGetArg(jsq, &elem); - res = !recursiveExecute(&elem, jb, jsqLeftArg); + res = !recursiveExecute(&elem, jb, jsqLeftArg, ra); break; case jqiKey: if (JsonbType(jb) == jbvObject) { @@ -438,15 +467,24 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) if (v != NULL) { - jsqGetNext(jsq, &elem); - res = recursiveExecute(&elem, v, NULL); + if (jsqGetNext(jsq, &elem) == false) + { + appendResult(ra, v); + res = true; + } + else + res = recursiveExecute(&elem, v, NULL, ra); pfree(v); } } break; case jqiCurrent: - jsqGetNext(jsq, &elem); - if (JsonbType(jb) == jbvScalar) + if (jsqGetNext(jsq, &elem) == false) + { + appendResult(ra, jb); + res = true; + } + else if (JsonbType(jb) == jbvScalar) { JsonbIterator *it; int32 r; @@ -462,26 +500,34 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) r = JsonbIteratorNext(&it, &v, true); Assert(r == WJB_ELEM); - res = recursiveExecute(&elem, &v, jsqLeftArg); + res = recursiveExecute(&elem, &v, jsqLeftArg, ra); } else { - res = recursiveExecute(&elem, jb, jsqLeftArg); + res = recursiveExecute(&elem, jb, jsqLeftArg, ra); } break; case jqiAny: - jsqGetNext(jsq, &elem); - if (recursiveExecute(&elem, jb, NULL)) + if (jsqGetNext(jsq, &elem) == false) + { + res = true; + appendResult(ra, jb); + } + else if (recursiveExecute(&elem, jb, NULL, ra)) res = true; else if (jb->type == jbvBinary) - res = recursiveAny(&elem, jb); + res = recursiveAny(&elem, jb, ra); break; case jqiAll: - jsqGetNext(jsq, &elem); - if ((res = recursiveExecute(&elem, jb, NULL)) == true) + if (jsqGetNext(jsq, &elem) == false) + { + res = true; + appendResult(ra, jb); + } + if ((res = recursiveExecute(&elem, jb, NULL, ra)) == true) { if (jb->type == jbvBinary) - res = recursiveAll(&elem, jb); + res = recursiveAll(&elem, jb, ra); } break; case jqiAnyArray: @@ -491,10 +537,23 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) JsonbIterator *it; int32 r; JsonbValue v; + bool anyres = false; + bool hasNext; - jsqGetNext(jsq, &elem); + hasNext = jsqGetNext(jsq, &elem); it = JsonbIteratorInit(jb->val.binary.data); + if (hasNext == false) + { + res = true; + + while(ra && (r = JsonbIteratorNext(&it, &v, true)) != WJB_DONE) + if (r == WJB_ELEM) + appendResult(ra, &v); + + break; + } + if (jsq->type == jqiAllArray) res = true; @@ -502,11 +561,13 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) { if (r == WJB_ELEM) { - res = recursiveExecute(&elem, &v, NULL); + res = recursiveExecute(&elem, &v, NULL, ra); if (jsq->type == jqiAnyArray) { - if (res == true) + anyres |= res; + if (res == true && + (ra == NULL || ra->missAppend == true)) break; } else if (jsq->type == jqiAllArray) @@ -516,6 +577,9 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) } } } + + if (jsq->type == jqiAnyArray) + res = anyres; } break; case jqiIndexArray: @@ -523,12 +587,19 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) { JsonbValue *v; - jsqGetNext(jsq, &elem); - v = getIthJsonbValueFromContainer(jb->val.binary.data, jsq->arrayIndex); - res = v && recursiveExecute(&elem, v, NULL); + if (v) + { + if (jsqGetNext(jsq, &elem) == false) + { + res = true; + appendResult(ra, v); + } + else + res = recursiveExecute(&elem, v, NULL, ra); + } } break; case jqiAnyKey: @@ -538,10 +609,23 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) JsonbIterator *it; int32 r; JsonbValue v; + bool anyres = false; + bool hasNext; - jsqGetNext(jsq, &elem); + hasNext = jsqGetNext(jsq, &elem); it = JsonbIteratorInit(jb->val.binary.data); + if (hasNext == false) + { + res = true; + + while(ra && (r = JsonbIteratorNext(&it, &v, true)) != WJB_DONE) + if (r == WJB_VALUE) + appendResult(ra, &v); + + break; + } + if (jsq->type == jqiAllKey) res = true; @@ -549,11 +633,13 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) { if (r == WJB_VALUE) { - res = recursiveExecute(&elem, &v, NULL); + res = recursiveExecute(&elem, &v, NULL, ra); if (jsq->type == jqiAnyKey) { - if (res == true) + anyres |= res; + if (res == true && + (ra == NULL || ra->missAppend == true)) break; } else if (jsq->type == jqiAllKey) @@ -563,6 +649,9 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) } } } + + if (jsq->type == jqiAnyKey) + res = anyres; } break; case jqiEqual: @@ -579,7 +668,7 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) break; case jqiLength: jsqGetNext(jsq, &elem); - res = recursiveExecute(&elem, jb, jsq); + res = recursiveExecute(&elem, jb, jsq, ra); break; case jqiIs: if (JsonbType(jb) == jbvScalar) @@ -605,6 +694,27 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg) res = (jsqGetIsType(jsq) == JsonbType(jb)); } break; + case jqiFilter: + { + bool saveMissAppend = (ra) ? ra->missAppend : true; + + jsqGetArg(jsq, &elem); + if (ra) + ra->missAppend = true; + res = recursiveExecute(&elem, jb, jsqLeftArg, ra); + if (ra) + ra->missAppend = saveMissAppend; + if (res) { + if (jsqGetNext(jsq, &elem) == false) + { + appendResult(ra, jb); + res = true; + } + else + res = recursiveExecute(&elem, jb, jsqLeftArg, ra); + } + } + break; default: elog(ERROR,"Wrong state: %d", jsq->type); } @@ -620,7 +730,7 @@ jsquery_json_exec(PG_FUNCTION_ARGS) Jsonb *jb = PG_GETARG_JSONB(1); bool res; JsonbValue jbv; - JsQueryItem jsq; + JsQueryItem jsq; jbv.type = jbvBinary; jbv.val.binary.data = &jb->root; @@ -628,7 +738,7 @@ jsquery_json_exec(PG_FUNCTION_ARGS) jsqInit(&jsq, jq); - res = recursiveExecute(&jsq, &jbv, NULL); + res = recursiveExecute(&jsq, &jbv, NULL, NULL); PG_FREE_IF_COPY(jq, 0); PG_FREE_IF_COPY(jb, 1); @@ -652,7 +762,7 @@ json_jsquery_exec(PG_FUNCTION_ARGS) jsqInit(&jsq, jq); - res = recursiveExecute(&jsq, &jbv, NULL); + res = recursiveExecute(&jsq, &jbv, NULL, NULL); PG_FREE_IF_COPY(jb, 0); PG_FREE_IF_COPY(jq, 1); @@ -660,6 +770,43 @@ json_jsquery_exec(PG_FUNCTION_ARGS) PG_RETURN_BOOL(res); } +PG_FUNCTION_INFO_V1(json_jsquery_filter); +Datum +json_jsquery_filter(PG_FUNCTION_ARGS) +{ + Jsonb *jb = PG_GETARG_JSONB(0); + JsQuery *jq = PG_GETARG_JSQUERY(1); + Jsonb *res = NULL; + JsonbValue jbv; + JsQueryItem jsq; + ResultAccum ra; + + jbv.type = jbvBinary; + jbv.val.binary.data = &jb->root; + jbv.val.binary.len = VARSIZE_ANY_EXHDR(jb); + + jsqInit(&jsq, jq); + memset(&ra, 0, sizeof(ra)); + + recursiveExecute(&jsq, &jbv, NULL, &ra); + + if (ra.jbArrayState) + { + res = JsonbValueToJsonb( + pushJsonbValue(&ra.jbArrayState, WJB_END_ARRAY, NULL) + ); + } + + PG_FREE_IF_COPY(jb, 0); + PG_FREE_IF_COPY(jq, 1); + + if (res) + PG_RETURN_JSONB(res); + else + PG_RETURN_NULL(); +} + + static int compareJsQuery(JsQueryItem *v1, JsQueryItem *v2) { @@ -682,6 +829,7 @@ compareJsQuery(JsQueryItem *v1, JsQueryItem *v2) case jqiAll: case jqiAllArray: case jqiAllKey: + case jqiFilter: break; case jqiIndexArray: if (v1->arrayIndex != v2->arrayIndex) @@ -980,6 +1128,7 @@ hashJsQuery(JsQueryItem *v, pg_crc32 *crc) case jqiAll: case jqiAllArray: case jqiAllKey: + case jqiFilter: break; case jqiIndexArray: COMP_CRC32(*crc, &v->arrayIndex, sizeof(v->arrayIndex)); diff --git a/jsquery_scan.l b/jsquery_scan.l index e73bdd7..65bd6ba 100644 --- a/jsquery_scan.l +++ b/jsquery_scan.l @@ -48,8 +48,8 @@ static void parseUnicode(char *s, int l); %x xNONQUOTED %x xCOMMENT -special [\%\$\.\[\]\(\)\|\&\!\=\<\>\@\#\,\*:] -any [^\%\$\.\[\]\(\)\|\&\!\=\<\>\@\#\,\* \t\n\r\f\\\"\/:] +special [\?\%\$\.\[\]\(\)\|\&\!\=\<\>\@\#\,\*:] +any [^\?\%\$\.\[\]\(\)\|\&\!\=\<\>\@\#\,\* \t\n\r\f\\\"\/:] blank [ \t\n\r\f] unicode \\u[0-9A-Fa-f]{4} diff --git a/jsquery_support.c b/jsquery_support.c index ee63c8c..8f95840 100644 --- a/jsquery_support.c +++ b/jsquery_support.c @@ -112,6 +112,7 @@ jsqInitByBuffer(JsQueryItem *v, char *base, int32 pos) case jqiOverlap: case jqiIn: case jqiNot: + case jqiFilter: read_int32(v->arg, base, pos); break; default: @@ -132,6 +133,7 @@ jsqGetArg(JsQueryItem *v, JsQueryItem *a) v->type == jqiContains || v->type == jqiContained || v->type == jqiOverlap || + v->type == jqiFilter || v->type == jqiIn || v->type == jqiNot ); @@ -154,6 +156,7 @@ jsqGetNext(JsQueryItem *v, JsQueryItem *a) v->type == jqiAllArray || v->type == jqiAllKey || v->type == jqiCurrent || + v->type == jqiFilter || v->type == jqiLength ); diff --git a/sql/jsquery.sql b/sql/jsquery.sql index d264955..48087b0 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -296,6 +296,36 @@ select '{"a":[1,2]}' @@ '*.@# in (2, 4)'::jsquery; select '{"a":[1,2]}' @@ '*.@# ($ = 4 or $ = 2)'::jsquery; select '{"a":[1,2]}' @@ '@# = 1'::jsquery; +--filter +select '?( not b>0). x'::jsquery; +select 'a.?(b>0 and x= 0 ) .c'::jsquery; +select 'a.$. ?(b>0 and x= 0 ) . c.k'::jsquery; +select 'a.$.? (b>0 and x.*= 0 ).c.k'::jsquery; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a < 0) (b=20)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 0) (b=20)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 1) (b=20)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 2) (b=20)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 3) (b=20)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#.a'; +select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#. ?(a > 1). b'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '# . ?(a > 1)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '%'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '%'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 )'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 ).$'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( % > 2 )'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 0 )'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 2 )'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '#'; +select '[1,2,3]'::jsonb ~~ '#'; +select '[1,2,3]'::jsonb ~~ '#. ?($ > 2)'; +select '[1,2,3]'::jsonb ~~ '#. ?($ > 2).$'; +select '[1,2,3]'::jsonb ~~ ' ?(#.$ > 2).$'; +select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 2).$'; +select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 0).$'; +select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '*.?(c >0)'; +select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '?(*.c >0)'; + --ALL select 'a.*: = 4'::jsquery; select '%: = 4'::jsquery; From 351ac9e890f3b9e12b1f4fd19f89b74da753d54d Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Thu, 1 Feb 2018 21:37:03 +0300 Subject: [PATCH 04/53] add filter support to jsquery construction --- jsquery_constr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/jsquery_constr.c b/jsquery_constr.c index fcb9088..19b0878 100644 --- a/jsquery_constr.c +++ b/jsquery_constr.c @@ -137,6 +137,7 @@ copyJsQuery(StringInfo buf, JsQueryItem *jsq) case jqiAll: case jqiAllArray: case jqiAllKey: + case jqiFilter: break; default: elog(ERROR, "Unknown type: %d", jsq->type); From e76f92d534787bb1060687dc958f1d4a5343b564 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Fri, 2 Feb 2018 12:33:33 +0300 Subject: [PATCH 05/53] version 1.1 --- META.json | 2 +- Makefile | 2 +- jsquery--1.0--1.1.sql | 11 +++++++++++ jsquery--1.0.sql => jsquery--1.1.sql | 0 jsquery.control | 2 +- 5 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 jsquery--1.0--1.1.sql rename jsquery--1.0.sql => jsquery--1.1.sql (100%) diff --git a/META.json b/META.json index 694210c..b8cd2a8 100644 --- a/META.json +++ b/META.json @@ -50,4 +50,4 @@ "index", "search" ] -} \ No newline at end of file +} diff --git a/Makefile b/Makefile index 0892a24..cb56dd9 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ OBJS = jsonb_gin_ops.o jsquery_constr.o jsquery_extract.o \ jsquery_gram.o jsquery_io.o jsquery_op.o jsquery_support.o EXTENSION = jsquery -DATA = jsquery--1.0.sql +DATA = jsquery--1.1.sql jsquery--1.0--1.1.sql INCLUDES = jsquery.h REGRESS = jsquery diff --git a/jsquery--1.0--1.1.sql b/jsquery--1.0--1.1.sql new file mode 100644 index 0000000..db16070 --- /dev/null +++ b/jsquery--1.0--1.1.sql @@ -0,0 +1,11 @@ +CREATE FUNCTION json_jsquery_filter(jsonb, jsquery) + RETURNS jsonb + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +CREATE OPERATOR ~~ ( + LEFTARG = jsonb, + RIGHTARG = jsquery, + PROCEDURE = json_jsquery_filter +); + diff --git a/jsquery--1.0.sql b/jsquery--1.1.sql similarity index 100% rename from jsquery--1.0.sql rename to jsquery--1.1.sql diff --git a/jsquery.control b/jsquery.control index 94510c8..d95ba24 100644 --- a/jsquery.control +++ b/jsquery.control @@ -1,6 +1,6 @@ # jsquery extension comment = 'data type for jsonb inspection' -default_version = '1.0' +default_version = '1.1' module_pathname = '$libdir/jsquery' relocatable = true From 4f82c4a22b789386e3b36e463016ca4ab4b09cd9 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Wed, 7 Feb 2018 18:36:32 +0300 Subject: [PATCH 06/53] fix wrong output of filter in jsquery, improve tests --- expected/jsquery.out | 30 +++++++++++++++++++++--------- jsquery_io.c | 2 ++ sql/jsquery.sql | 2 ++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/expected/jsquery.out b/expected/jsquery.out index ccab908..8a70a4f 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -1454,21 +1454,21 @@ select '?( not b>0). x'::jsquery; (1 row) select 'a.?(b>0 and x= 0 ) .c'::jsquery; - jsquery ------------------------------------ - "a" ?(("b" > 0 AND "x" = 0)) ."c" + jsquery +------------------------------------ + "a". ?(("b" > 0 AND "x" = 0)) ."c" (1 row) select 'a.$. ?(b>0 and x= 0 ) . c.k'::jsquery; - jsquery ------------------------------------------ - "a".$ ?(("b" > 0 AND "x" = 0)) ."c"."k" + jsquery +------------------------------------------ + "a".$. ?(("b" > 0 AND "x" = 0)) ."c"."k" (1 row) select 'a.$.? (b>0 and x.*= 0 ).c.k'::jsquery; - jsquery -------------------------------------------- - "a".$ ?(("b" > 0 AND "x".* = 0)) ."c"."k" + jsquery +-------------------------------------------- + "a".$. ?(("b" > 0 AND "x".* = 0)) ."c"."k" (1 row) select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a < 0) (b=20)'; @@ -1615,6 +1615,18 @@ select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '?(*.c >0)'; [{"a": {"b": {"c": 1}}}] (1 row) +select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term.#. ? ( $ = "NYC")'; + ?column? +---------- + ["NYC"] +(1 row) + +select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term. ? ( # = "NYC")'; + ?column? +------------------ + [["NYC", "CYN"]] +(1 row) + --ALL select 'a.*: = 4'::jsquery; jsquery diff --git a/jsquery_io.c b/jsquery_io.c index 5a7c458..4bee263 100644 --- a/jsquery_io.c +++ b/jsquery_io.c @@ -378,6 +378,8 @@ printJsQueryItem(StringInfo buf, JsQueryItem *v, bool inKey, bool printBracketes appendStringInfo(buf, "#%u", v->arrayIndex); break; case jqiFilter: + if (inKey) + appendStringInfoChar(buf, '.'); appendBinaryStringInfo(buf, " ?(", 3); jsqGetArg(v, &elem); printJsQueryItem(buf, &elem, false, false); diff --git a/sql/jsquery.sql b/sql/jsquery.sql index 48087b0..7cbb852 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -325,6 +325,8 @@ select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 2).$'; select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 0).$'; select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '*.?(c >0)'; select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '?(*.c >0)'; +select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term.#. ? ( $ = "NYC")'; +select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term. ? ( # = "NYC")'; --ALL select 'a.*: = 4'::jsquery; From a2ed9820a7cc80b7aea64b072e137e71f659fda6 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Thu, 8 Feb 2018 12:59:00 +0300 Subject: [PATCH 07/53] dummy support of filter in gin index (just ignore), fix support of path existing --- expected/jsquery.out | 57 +++++++++++++++++++++++++++++++++++++++++++- jsonb_gin_ops.c | 4 ++-- jsquery_extract.c | 2 ++ jsquery_gram.y | 4 ++-- sql/jsquery.sql | 10 ++++++++ 5 files changed, 72 insertions(+), 5 deletions(-) diff --git a/expected/jsquery.out b/expected/jsquery.out index 8a70a4f..b5ca73a 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -67,7 +67,7 @@ select '* < 13 AND #.zxc"x" = "true"'::jsquery; ERROR: bad jsquery representation LINE 1: select '* < 13 AND #.zxc"x" = "true"'::jsquery; ^ -DETAIL: syntax error, unexpected STRING_P at or near """ +DETAIL: syntax error, unexpected STRING_P, expecting $end at or near """ select 'a < 1'::jsquery; jsquery --------- @@ -1856,6 +1856,54 @@ select '[16]' @@ '(@# > 0 and #: = 16)'::jsquery; t (1 row) +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b or b.d'; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c or b.d'; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.d'; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.c'; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b and b.d'; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.d'; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.b'; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g and b.d'; + ?column? +---------- + f +(1 row) + --extract entries for index scan SELECT gin_debug_query_path_value('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5'); gin_debug_query_path_value @@ -2236,6 +2284,13 @@ SELECT gin_debug_query_value_path('*.@# ($ = 4 or $ = 2)'); (1 row) +SELECT gin_debug_query_value_path('tags.#.term. ? ( # = "NYC").x > 0'); + gin_debug_query_value_path +------------------------------ + tags.#.term.x > 0 , entry 0 + + +(1 row) + ---table and index select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 0; count diff --git a/jsonb_gin_ops.c b/jsonb_gin_ops.c index fe2a543..49dde46 100644 --- a/jsonb_gin_ops.c +++ b/jsonb_gin_ops.c @@ -1,13 +1,13 @@ /*------------------------------------------------------------------------- * * jsonb_gin_ops.c - * Support GIN over jsonb with jsquery operation + * Support GIN over jsonb with jsquery operation * * Copyright (c) 2014, PostgreSQL Global Development Group * Author: Alexander Korotkov * * IDENTIFICATION - * contrib/jsquery/jsonb_gin_ops.c + * contrib/jsquery/jsonb_gin_ops.c * *------------------------------------------------------------------------- */ diff --git a/jsquery_extract.c b/jsquery_extract.c index 7cacc18..4db3041 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -130,6 +130,8 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) pathItem->parent = path; jsqGetNext(jsq, &elem); return recursiveExtract(&elem, not, true, pathItem); + case jqiFilter: + /* ignore filter for now */ case jqiCurrent: jsqGetNext(jsq, &elem); return recursiveExtract(&elem, not, indirect, path); diff --git a/jsquery_gram.y b/jsquery_gram.y index 4d1c28a..2d6d531 100644 --- a/jsquery_gram.y +++ b/jsquery_gram.y @@ -250,7 +250,6 @@ makeItemList(List *list) { result: expr { *result = $1; } - | path { *result = makeItemList($1); } | /* EMPTY */ { *result = NULL; } ; @@ -307,7 +306,8 @@ right_expr: ; expr: - path right_expr { $$ = makeItemList(lappend($1, $2)); } + path { $$ = makeItemList($1); } + | path right_expr { $$ = makeItemList(lappend($1, $2)); } | path HINT_P right_expr { $3->hint = $2; $$ = makeItemList(lappend($1, $3)); } | NOT_P expr { $$ = makeItemUnary(jqiNot, $2); } /* diff --git a/sql/jsquery.sql b/sql/jsquery.sql index 7cbb852..de75523 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -369,6 +369,15 @@ SELECT 'test.# IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,2 select '[]' @@ '(@# > 0 and #: = 16)'::jsquery; select '[16]' @@ '(@# > 0 and #: = 16)'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b or b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c or b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.c'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.b'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g and b.d'; + --extract entries for index scan SELECT gin_debug_query_path_value('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5'); @@ -419,6 +428,7 @@ SELECT gin_debug_query_value_path('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)') SELECT gin_debug_query_value_path('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)'); SELECT gin_debug_query_value_path('(@# > 0 and #: = 16)'); SELECT gin_debug_query_value_path('*.@# ($ = 4 or $ = 2)'); +SELECT gin_debug_query_value_path('tags.#.term. ? ( # = "NYC").x > 0'); ---table and index From f1ebe1c23fe3e00d24d1b428309f2e0741398a72 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Thu, 8 Feb 2018 15:42:26 +0300 Subject: [PATCH 08/53] correct work for logical expression in ~~ --- expected/jsquery.out | 84 ++++++++++++++++++++++++++++++++++++++++++++ jsquery_op.c | 69 +++++++++++++++++++++++++++++++----- sql/jsquery.sql | 15 ++++++++ 3 files changed, 160 insertions(+), 8 deletions(-) diff --git a/expected/jsquery.out b/expected/jsquery.out index b5ca73a..54b2b95 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -1904,6 +1904,90 @@ select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g and b.d'; f (1 row) +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.d'; + ?column? +---------- + [1, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.c'; + ?column? +---------- + +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.d or b.c)'; + ?column? +---------- + [1, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.c or b.d)'; + ?column? +---------- + [1, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and a.c and b.d'; + ?column? +----------- + [1, 2, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.b or a.c) and b.d'; + ?column? +---------- + [1, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.c) and b.d'; + ?column? +---------- + [2, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.g) and b.d'; + ?column? +---------- + +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b or (b.d or b.c)'; + ?column? +---------- + [1] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b or a.c)'; + ?column? +---------- + [3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b and a.c)'; + ?column? +---------- + [3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.f or (a.b and a.c)'; + ?column? +---------- + [1, 2] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'; + ?column? +----------- + [3, 1, 2] +(1 row) + +select '{"a": {"b": [6,5,4], "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'; + ?column? +------------------- + [3, [6, 5, 4], 2] +(1 row) + --extract entries for index scan SELECT gin_debug_query_path_value('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5'); gin_debug_query_path_value diff --git a/jsquery_op.c b/jsquery_op.c index db2ca57..1cbfa0a 100644 --- a/jsquery_op.c +++ b/jsquery_op.c @@ -51,6 +51,27 @@ appendResult(ResultAccum *ra, JsonbValue *jb) pushJsonbValue(&ra->jbArrayState, WJB_ELEM, jb); } +static void +concatResult(ResultAccum *ra, JsonbParseState *a, JsonbParseState *b) +{ + Jsonb *value; + JsonbIterator *it; + int32 r; + JsonbValue v; + + Assert(a); + Assert(b); + + ra->jbArrayState = a; + + value = JsonbValueToJsonb(pushJsonbValue(&b, WJB_END_ARRAY, NULL)); + it = JsonbIteratorInit(&value->root); + + while((r = JsonbIteratorNext(&it, &v, true)) != WJB_DONE) + if (r == WJB_ELEM) + pushJsonbValue(&ra->jbArrayState, WJB_ELEM, &v); +} + static int compareNumeric(Numeric a, Numeric b) { @@ -435,14 +456,37 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg, switch(jsq->type) { case jqiAnd: - jsqGetLeftArg(jsq, &elem); - res = recursiveExecute(&elem, jb, jsqLeftArg, ra); - if (res == true) { - jsqGetRightArg(jsq, &elem); + JsonbParseState *saveJbArrayState = NULL; + + jsqGetLeftArg(jsq, &elem); + if (ra && ra->missAppend == false) + { + saveJbArrayState = ra->jbArrayState; + ra->jbArrayState = NULL; + } + res = recursiveExecute(&elem, jb, jsqLeftArg, ra); + if (res == true) + { + jsqGetRightArg(jsq, &elem); + res = recursiveExecute(&elem, jb, jsqLeftArg, ra); + } + + if (ra && ra->missAppend == false) + { + if (res == true) + { + if (saveJbArrayState != NULL) + /* append args lists to current */ + concatResult(ra, saveJbArrayState, ra->jbArrayState); + } + else + ra->jbArrayState = saveJbArrayState; + } + + break; } - break; case jqiOr: jsqGetLeftArg(jsq, &elem); res = recursiveExecute(&elem, jb, jsqLeftArg, ra); @@ -453,9 +497,18 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg, } break; case jqiNot: - jsqGetArg(jsq, &elem); - res = !recursiveExecute(&elem, jb, jsqLeftArg, ra); - break; + { + bool saveMissAppend = (ra) ? ra->missAppend : true; + + jsqGetArg(jsq, &elem); + if (ra) + ra->missAppend = true; + res = !recursiveExecute(&elem, jb, jsqLeftArg, ra); + if (ra) + ra->missAppend = saveMissAppend; + + break; + } case jqiKey: if (JsonbType(jb) == jbvObject) { JsonbValue *v, key; diff --git a/sql/jsquery.sql b/sql/jsquery.sql index de75523..3450bdc 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -378,6 +378,21 @@ select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.d'; select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.b'; select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.c'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.d or b.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.c or b.d)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and a.c and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.b or a.c) and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.c) and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.g) and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b or (b.d or b.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b or a.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b and a.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.f or (a.b and a.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'; +select '{"a": {"b": [6,5,4], "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'; + --extract entries for index scan SELECT gin_debug_query_path_value('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5'); From 7f90adf7a789ab49de421311efc98846fbe2b12f Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Thu, 15 Feb 2018 02:27:41 +0300 Subject: [PATCH 09/53] Add travis-ci scripts which are simplified version of those of pg_pathman. --- .travis.yml | 35 +++++++++++++ README.md | 3 ++ travis/dep-ubuntu-llvm.sh | 4 ++ travis/dep-ubuntu-postgres.sh | 4 ++ travis/llvm-snapshot.gpg.key | 52 ++++++++++++++++++++ travis/pg-travis-test.sh | 93 +++++++++++++++++++++++++++++++++++ travis/postgresql.gpg.key | 77 +++++++++++++++++++++++++++++ 7 files changed, 268 insertions(+) create mode 100644 .travis.yml create mode 100755 travis/dep-ubuntu-llvm.sh create mode 100755 travis/dep-ubuntu-postgres.sh create mode 100644 travis/llvm-snapshot.gpg.key create mode 100755 travis/pg-travis-test.sh create mode 100644 travis/postgresql.gpg.key diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2f24ce5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +os: + - linux + +sudo: required +dist: trusty + +language: c + +compiler: + - clang + - gcc + +before_install: + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -y install -qq wget ca-certificates; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then source ./travis/dep-ubuntu-postgres.sh; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then source ./travis/dep-ubuntu-llvm.sh; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq; fi + +env: + global: + - LLVM_VER=4.0 + matrix: + - PG_VER=10 CHECK_CODE=true + - PG_VER=10 CHECK_CODE=false + - PG_VER=9.6 CHECK_CODE=true + - PG_VER=9.6 CHECK_CODE=false + - PG_VER=9.5 CHECK_CODE=true + - PG_VER=9.5 CHECK_CODE=false + - PG_VER=9.4 CHECK_CODE=true + - PG_VER=9.4 CHECK_CODE=false + +script: bash ./travis/pg-travis-test.sh + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index d96ad69..3ce8dc8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Build Status](https://travis-ci.org/postgrespro/jsquery.svg?branch=master)](https://travis-ci.org/postgrespro/jsquery) +[![codecov](https://codecov.io/gh/postgrespro/jsquery/branch/master/graph/badge.svg)](https://codecov.io/gh/postgrespro/jsquery) + JsQuery – json query language with GIN indexing support ======================================================= diff --git a/travis/dep-ubuntu-llvm.sh b/travis/dep-ubuntu-llvm.sh new file mode 100755 index 0000000..e640d5b --- /dev/null +++ b/travis/dep-ubuntu-llvm.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cat ./travis/llvm-snapshot.gpg.key | sudo apt-key add - +echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-$(lsb_release -cs)-$LLVM_VER main" | sudo tee /etc/apt/sources.list.d/llvm.list diff --git a/travis/dep-ubuntu-postgres.sh b/travis/dep-ubuntu-postgres.sh new file mode 100755 index 0000000..41c7d34 --- /dev/null +++ b/travis/dep-ubuntu-postgres.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cat ./travis/postgresql.gpg.key | sudo apt-key add - +echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main $PG_VER" | sudo tee /etc/apt/sources.list.d/pgdg.list diff --git a/travis/llvm-snapshot.gpg.key b/travis/llvm-snapshot.gpg.key new file mode 100644 index 0000000..aa6b105 --- /dev/null +++ b/travis/llvm-snapshot.gpg.key @@ -0,0 +1,52 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.4.12 (GNU/Linux) + +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 +bXb5c6gCHESH5PXwPU4jQEE7Ib9J6sbk7ZT2Mw== +=j+4q +-----END PGP PUBLIC KEY BLOCK----- diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh new file mode 100755 index 0000000..1f56fe8 --- /dev/null +++ b/travis/pg-travis-test.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +set -eux + +sudo apt-get update + + +# required packages +apt_packages="postgresql-$PG_VER postgresql-server-dev-$PG_VER postgresql-common build-essential flex bison" + +# exit code +status=0 + +# pg_config path +pg_ctl_path=/usr/lib/postgresql/$PG_VER/bin/pg_ctl +initdb_path=/usr/lib/postgresql/$PG_VER/bin/initdb +config_path=/usr/lib/postgresql/$PG_VER/bin/pg_config + + +# bug: http://www.postgresql.org/message-id/20130508192711.GA9243@msgid.df7cb.de +sudo update-alternatives --remove-all postmaster.1.gz + +# stop all existing instances (because of https://github.com/travis-ci/travis-cookbooks/pull/221) +sudo service postgresql stop +# ... and make sure they don't come back +echo 'exit 0' | sudo tee /etc/init.d/postgresql +sudo chmod a+x /etc/init.d/postgresql + +# install required packages +sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages + + +# perform code analysis if necessary +if [ $CHECK_CODE = "true" ]; then + + if [ "$CC" = "clang" ]; then + sudo apt-get -y install -qq clang-$LLVM_VER + + scan-build-$LLVM_VER --status-bugs make USE_PGXS=1 PG_CONFIG=$config_path || status=$? + exit $status + + elif [ "$CC" = "gcc" ]; then + sudo apt-get -y install -qq cppcheck + + cppcheck --template "{file} ({line}): {severity} ({id}): {message}" \ + --enable=warning,portability,performance \ + --suppress=redundantAssignment \ + --suppress=uselessAssignmentPtrArg \ + --suppress=incorrectStringBooleanError \ + --std=c89 *.c *.h 2> cppcheck.log + + if [ -s cppcheck.log ]; then + cat cppcheck.log + status=1 # error + fi + + exit $status + fi + + # don't forget to "make clean" + make clean USE_PGXS=1 PG_CONFIG=$config_path +fi + + +# create cluster 'test' +CLUSTER_PATH=$(pwd)/test_cluster +$initdb_path -D $CLUSTER_PATH -U $USER -A trust + +# build jsquery (using CFLAGS_SL for gcov) +make USE_PGXS=1 PG_CONFIG=$config_path CFLAGS_SL="$($config_path --cflags_sl) -coverage" +sudo make install USE_PGXS=1 PG_CONFIG=$config_path + +# check build +status=$? +if [ $status -ne 0 ]; then exit $status; fi + +# set permission to write postgres locks +sudo chown $USER /var/run/postgresql/ + +# start cluster 'test' +echo "port = 55435" >> $CLUSTER_PATH/postgresql.conf +$pg_ctl_path -D $CLUSTER_PATH start -l postgres.log -w + +# run regression tests +PGPORT=55435 PGUSER=$USER PG_CONFIG=$config_path make installcheck USE_PGXS=1 || status=$? + +# show diff if it exists +if test -f regression.diffs; then cat regression.diffs; fi + +#generate *.gcov files +gcov *.c *.h + +exit $status diff --git a/travis/postgresql.gpg.key b/travis/postgresql.gpg.key new file mode 100644 index 0000000..8480576 --- /dev/null +++ b/travis/postgresql.gpg.key @@ -0,0 +1,77 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +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 +=DA1T +-----END PGP PUBLIC KEY BLOCK----- From 10650ecf66c27e116af3f366058517df28901702 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Thu, 15 Feb 2018 02:54:17 +0300 Subject: [PATCH 10/53] Some improvements to static analyzer checking. --- Makefile | 4 ++++ jsonb_gin_ops.c | 3 ++- jsquery_op.c | 2 +- travis/pg-travis-test.sh | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0892a24..d7d415c 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,10 @@ include $(top_builddir)/src/Makefile.global include $(top_srcdir)/contrib/contrib-global.mk endif +ifdef USE_ASSERT_CHECKING +override CFLAGS += -DUSE_ASSERT_CHECKING +endif + jsquery_gram.o: jsquery_scan.c jsquery_gram.c: BISONFLAGS += -d diff --git a/jsonb_gin_ops.c b/jsonb_gin_ops.c index fe2a543..1040bdd 100644 --- a/jsonb_gin_ops.c +++ b/jsonb_gin_ops.c @@ -462,7 +462,7 @@ make_value_path_entry_handler(ExtractedNode *node, Pointer extra) { Entries *e = (Entries *)extra; uint32 hash; - bool lossy, partialMatch; + bool lossy, partialMatch = false; GINKey *key; KeyExtra *keyExtra; int result; @@ -1175,6 +1175,7 @@ gin_debug_query_path_value(PG_FUNCTION_ARGS) Entries e = {0}; char *s; + jq = PG_GETARG_JSQUERY(0); s = debugJsQuery(jq, make_path_value_entry_handler, check_path_value_entry_handler, (Pointer)&e); diff --git a/jsquery_op.c b/jsquery_op.c index 426257f..25545ff 100644 --- a/jsquery_op.c +++ b/jsquery_op.c @@ -221,7 +221,7 @@ checkScalarIn(JsQueryItem *jsq, JsonbValue *jb) static bool executeArrayOp(JsQueryItem *jsq, int32 op, JsonbValue *jb) { - int32 r; + int32 r = 0; /* keep static analyzer quiet */ JsonbIterator *it; JsonbValue v; JsQueryItem elem; diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 1f56fe8..0320878 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -36,7 +36,7 @@ if [ $CHECK_CODE = "true" ]; then if [ "$CC" = "clang" ]; then sudo apt-get -y install -qq clang-$LLVM_VER - scan-build-$LLVM_VER --status-bugs make USE_PGXS=1 PG_CONFIG=$config_path || status=$? + scan-build-$LLVM_VER --status-bugs make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path || status=$? exit $status elif [ "$CC" = "gcc" ]; then From 0dc0ef4cf765301ed6c35549b2e5f60f6f6f308c Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Thu, 15 Feb 2018 14:08:26 +0300 Subject: [PATCH 11/53] Disable deadcode.DeadStores in clang analyzer test deadcode.DeadStores errors seems to be inevitable when using Bison. --- travis/pg-travis-test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 0320878..1c192ab 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -36,7 +36,9 @@ if [ $CHECK_CODE = "true" ]; then if [ "$CC" = "clang" ]; then sudo apt-get -y install -qq clang-$LLVM_VER - scan-build-$LLVM_VER --status-bugs make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path || status=$? + scan-build-$LLVM_VER --status-bugs \ + -disable-checker deadcode.DeadStores \ + make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path || status=$? exit $status elif [ "$CC" = "gcc" ]; then From 580f6cb27cd92b32c08d6f668652c35f042b1920 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Thu, 15 Feb 2018 14:09:21 +0300 Subject: [PATCH 12/53] Fix some clang analyzer complaints. --- jsonb_gin_ops.c | 9 +++++++++ jsquery_extract.c | 1 + 2 files changed, 10 insertions(+) diff --git a/jsonb_gin_ops.c b/jsonb_gin_ops.c index 1040bdd..92acb52 100644 --- a/jsonb_gin_ops.c +++ b/jsonb_gin_ops.c @@ -691,6 +691,8 @@ gin_extract_jsonb_value_path_internal(Jsonb *jb, int32 *nentries, uint32 **bloom stack->parent = tmp; break; case WJB_KEY: + if (!stack) /* should never happen */ + elog(ERROR, "error jsonb iteration"); stack->hash = 0; JsonbHashScalarValue(&v, &stack->hash); break; @@ -709,6 +711,8 @@ gin_extract_jsonb_value_path_internal(Jsonb *jb, int32 *nentries, uint32 **bloom break; case WJB_END_OBJECT: /* Pop the stack */ + if (!stack) /* should never happen */ + elog(ERROR, "error jsonb iteration"); tmp = stack->parent; pfree(stack); stack = tmp; @@ -1109,6 +1113,9 @@ gin_extract_jsonb_path_value_internal(Jsonb *jb, int32 *nentries) entries = (Datum *) repalloc(entries, sizeof(Datum) * total); } + if (!stack) /* should never happen */ + elog(ERROR, "error jsonb iteration"); + switch (r) { case WJB_BEGIN_ARRAY: @@ -1131,6 +1138,8 @@ gin_extract_jsonb_path_value_internal(Jsonb *jb, int32 *nentries) break; case WJB_KEY: /* Initialize hash from parent */ + if (!stack->parent) /* should never happen */ + elog(ERROR, "error jsonb iteration"); stack->hash = stack->parent->hash; JsonbHashScalarValue(&v, &stack->hash); break; diff --git a/jsquery_extract.c b/jsquery_extract.c index 7cacc18..01956ae 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -48,6 +48,7 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) ExtractedNodeType type; JsQueryItem elem, e; + e.hint = false; check_stack_depth(); switch(jsq->type) From 18ed1a25936c6c363f399cc7ac583455b21666da Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Thu, 15 Feb 2018 02:27:41 +0300 Subject: [PATCH 13/53] Add travis-ci scripts which are simplified version of those of pg_pathman. --- .travis.yml | 35 +++++++++++++ README.md | 3 ++ travis/dep-ubuntu-llvm.sh | 4 ++ travis/dep-ubuntu-postgres.sh | 4 ++ travis/llvm-snapshot.gpg.key | 52 ++++++++++++++++++++ travis/pg-travis-test.sh | 93 +++++++++++++++++++++++++++++++++++ travis/postgresql.gpg.key | 77 +++++++++++++++++++++++++++++ 7 files changed, 268 insertions(+) create mode 100644 .travis.yml create mode 100755 travis/dep-ubuntu-llvm.sh create mode 100755 travis/dep-ubuntu-postgres.sh create mode 100644 travis/llvm-snapshot.gpg.key create mode 100755 travis/pg-travis-test.sh create mode 100644 travis/postgresql.gpg.key diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2f24ce5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +os: + - linux + +sudo: required +dist: trusty + +language: c + +compiler: + - clang + - gcc + +before_install: + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -y install -qq wget ca-certificates; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then source ./travis/dep-ubuntu-postgres.sh; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then source ./travis/dep-ubuntu-llvm.sh; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq; fi + +env: + global: + - LLVM_VER=4.0 + matrix: + - PG_VER=10 CHECK_CODE=true + - PG_VER=10 CHECK_CODE=false + - PG_VER=9.6 CHECK_CODE=true + - PG_VER=9.6 CHECK_CODE=false + - PG_VER=9.5 CHECK_CODE=true + - PG_VER=9.5 CHECK_CODE=false + - PG_VER=9.4 CHECK_CODE=true + - PG_VER=9.4 CHECK_CODE=false + +script: bash ./travis/pg-travis-test.sh + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index d96ad69..3ce8dc8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Build Status](https://travis-ci.org/postgrespro/jsquery.svg?branch=master)](https://travis-ci.org/postgrespro/jsquery) +[![codecov](https://codecov.io/gh/postgrespro/jsquery/branch/master/graph/badge.svg)](https://codecov.io/gh/postgrespro/jsquery) + JsQuery – json query language with GIN indexing support ======================================================= diff --git a/travis/dep-ubuntu-llvm.sh b/travis/dep-ubuntu-llvm.sh new file mode 100755 index 0000000..e640d5b --- /dev/null +++ b/travis/dep-ubuntu-llvm.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cat ./travis/llvm-snapshot.gpg.key | sudo apt-key add - +echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-$(lsb_release -cs)-$LLVM_VER main" | sudo tee /etc/apt/sources.list.d/llvm.list diff --git a/travis/dep-ubuntu-postgres.sh b/travis/dep-ubuntu-postgres.sh new file mode 100755 index 0000000..41c7d34 --- /dev/null +++ b/travis/dep-ubuntu-postgres.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cat ./travis/postgresql.gpg.key | sudo apt-key add - +echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main $PG_VER" | sudo tee /etc/apt/sources.list.d/pgdg.list diff --git a/travis/llvm-snapshot.gpg.key b/travis/llvm-snapshot.gpg.key new file mode 100644 index 0000000..aa6b105 --- /dev/null +++ b/travis/llvm-snapshot.gpg.key @@ -0,0 +1,52 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.4.12 (GNU/Linux) + +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 +bXb5c6gCHESH5PXwPU4jQEE7Ib9J6sbk7ZT2Mw== +=j+4q +-----END PGP PUBLIC KEY BLOCK----- diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh new file mode 100755 index 0000000..1f56fe8 --- /dev/null +++ b/travis/pg-travis-test.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +set -eux + +sudo apt-get update + + +# required packages +apt_packages="postgresql-$PG_VER postgresql-server-dev-$PG_VER postgresql-common build-essential flex bison" + +# exit code +status=0 + +# pg_config path +pg_ctl_path=/usr/lib/postgresql/$PG_VER/bin/pg_ctl +initdb_path=/usr/lib/postgresql/$PG_VER/bin/initdb +config_path=/usr/lib/postgresql/$PG_VER/bin/pg_config + + +# bug: http://www.postgresql.org/message-id/20130508192711.GA9243@msgid.df7cb.de +sudo update-alternatives --remove-all postmaster.1.gz + +# stop all existing instances (because of https://github.com/travis-ci/travis-cookbooks/pull/221) +sudo service postgresql stop +# ... and make sure they don't come back +echo 'exit 0' | sudo tee /etc/init.d/postgresql +sudo chmod a+x /etc/init.d/postgresql + +# install required packages +sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages + + +# perform code analysis if necessary +if [ $CHECK_CODE = "true" ]; then + + if [ "$CC" = "clang" ]; then + sudo apt-get -y install -qq clang-$LLVM_VER + + scan-build-$LLVM_VER --status-bugs make USE_PGXS=1 PG_CONFIG=$config_path || status=$? + exit $status + + elif [ "$CC" = "gcc" ]; then + sudo apt-get -y install -qq cppcheck + + cppcheck --template "{file} ({line}): {severity} ({id}): {message}" \ + --enable=warning,portability,performance \ + --suppress=redundantAssignment \ + --suppress=uselessAssignmentPtrArg \ + --suppress=incorrectStringBooleanError \ + --std=c89 *.c *.h 2> cppcheck.log + + if [ -s cppcheck.log ]; then + cat cppcheck.log + status=1 # error + fi + + exit $status + fi + + # don't forget to "make clean" + make clean USE_PGXS=1 PG_CONFIG=$config_path +fi + + +# create cluster 'test' +CLUSTER_PATH=$(pwd)/test_cluster +$initdb_path -D $CLUSTER_PATH -U $USER -A trust + +# build jsquery (using CFLAGS_SL for gcov) +make USE_PGXS=1 PG_CONFIG=$config_path CFLAGS_SL="$($config_path --cflags_sl) -coverage" +sudo make install USE_PGXS=1 PG_CONFIG=$config_path + +# check build +status=$? +if [ $status -ne 0 ]; then exit $status; fi + +# set permission to write postgres locks +sudo chown $USER /var/run/postgresql/ + +# start cluster 'test' +echo "port = 55435" >> $CLUSTER_PATH/postgresql.conf +$pg_ctl_path -D $CLUSTER_PATH start -l postgres.log -w + +# run regression tests +PGPORT=55435 PGUSER=$USER PG_CONFIG=$config_path make installcheck USE_PGXS=1 || status=$? + +# show diff if it exists +if test -f regression.diffs; then cat regression.diffs; fi + +#generate *.gcov files +gcov *.c *.h + +exit $status diff --git a/travis/postgresql.gpg.key b/travis/postgresql.gpg.key new file mode 100644 index 0000000..8480576 --- /dev/null +++ b/travis/postgresql.gpg.key @@ -0,0 +1,77 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +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 +=DA1T +-----END PGP PUBLIC KEY BLOCK----- From 9902ebc833faf6ad7f565f92f855c72cbb2e49e5 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Thu, 15 Feb 2018 02:54:17 +0300 Subject: [PATCH 14/53] Some improvements to static analyzer checking. --- Makefile | 4 ++++ jsonb_gin_ops.c | 3 ++- jsquery_op.c | 2 +- travis/pg-travis-test.sh | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index cb56dd9..b11a9b1 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,10 @@ include $(top_builddir)/src/Makefile.global include $(top_srcdir)/contrib/contrib-global.mk endif +ifdef USE_ASSERT_CHECKING +override CFLAGS += -DUSE_ASSERT_CHECKING +endif + jsquery_gram.o: jsquery_scan.c jsquery_gram.c: BISONFLAGS += -d diff --git a/jsonb_gin_ops.c b/jsonb_gin_ops.c index 49dde46..6da7498 100644 --- a/jsonb_gin_ops.c +++ b/jsonb_gin_ops.c @@ -462,7 +462,7 @@ make_value_path_entry_handler(ExtractedNode *node, Pointer extra) { Entries *e = (Entries *)extra; uint32 hash; - bool lossy, partialMatch; + bool lossy, partialMatch = false; GINKey *key; KeyExtra *keyExtra; int result; @@ -1175,6 +1175,7 @@ gin_debug_query_path_value(PG_FUNCTION_ARGS) Entries e = {0}; char *s; + jq = PG_GETARG_JSQUERY(0); s = debugJsQuery(jq, make_path_value_entry_handler, check_path_value_entry_handler, (Pointer)&e); diff --git a/jsquery_op.c b/jsquery_op.c index 1cbfa0a..b023de0 100644 --- a/jsquery_op.c +++ b/jsquery_op.c @@ -270,7 +270,7 @@ checkScalarIn(JsQueryItem *jsq, JsonbValue *jb) static bool executeArrayOp(JsQueryItem *jsq, int32 op, JsonbValue *jb) { - int32 r; + int32 r = 0; /* keep static analyzer quiet */ JsonbIterator *it; JsonbValue v; JsQueryItem elem; diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 1f56fe8..0320878 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -36,7 +36,7 @@ if [ $CHECK_CODE = "true" ]; then if [ "$CC" = "clang" ]; then sudo apt-get -y install -qq clang-$LLVM_VER - scan-build-$LLVM_VER --status-bugs make USE_PGXS=1 PG_CONFIG=$config_path || status=$? + scan-build-$LLVM_VER --status-bugs make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path || status=$? exit $status elif [ "$CC" = "gcc" ]; then From 6f1efc3b62c812af68f2acb338605a8f98629202 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Thu, 15 Feb 2018 14:08:26 +0300 Subject: [PATCH 15/53] Disable deadcode.DeadStores in clang analyzer test deadcode.DeadStores errors seems to be inevitable when using Bison. --- travis/pg-travis-test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 0320878..1c192ab 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -36,7 +36,9 @@ if [ $CHECK_CODE = "true" ]; then if [ "$CC" = "clang" ]; then sudo apt-get -y install -qq clang-$LLVM_VER - scan-build-$LLVM_VER --status-bugs make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path || status=$? + scan-build-$LLVM_VER --status-bugs \ + -disable-checker deadcode.DeadStores \ + make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path || status=$? exit $status elif [ "$CC" = "gcc" ]; then From 0c5bb5cca8c78e336e40152b80e30fff46202f83 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Thu, 15 Feb 2018 14:09:21 +0300 Subject: [PATCH 16/53] Fix some clang analyzer complaints. --- jsonb_gin_ops.c | 9 +++++++++ jsquery_extract.c | 1 + 2 files changed, 10 insertions(+) diff --git a/jsonb_gin_ops.c b/jsonb_gin_ops.c index 6da7498..eef8a0d 100644 --- a/jsonb_gin_ops.c +++ b/jsonb_gin_ops.c @@ -691,6 +691,8 @@ gin_extract_jsonb_value_path_internal(Jsonb *jb, int32 *nentries, uint32 **bloom stack->parent = tmp; break; case WJB_KEY: + if (!stack) /* should never happen */ + elog(ERROR, "error jsonb iteration"); stack->hash = 0; JsonbHashScalarValue(&v, &stack->hash); break; @@ -709,6 +711,8 @@ gin_extract_jsonb_value_path_internal(Jsonb *jb, int32 *nentries, uint32 **bloom break; case WJB_END_OBJECT: /* Pop the stack */ + if (!stack) /* should never happen */ + elog(ERROR, "error jsonb iteration"); tmp = stack->parent; pfree(stack); stack = tmp; @@ -1109,6 +1113,9 @@ gin_extract_jsonb_path_value_internal(Jsonb *jb, int32 *nentries) entries = (Datum *) repalloc(entries, sizeof(Datum) * total); } + if (!stack) /* should never happen */ + elog(ERROR, "error jsonb iteration"); + switch (r) { case WJB_BEGIN_ARRAY: @@ -1131,6 +1138,8 @@ gin_extract_jsonb_path_value_internal(Jsonb *jb, int32 *nentries) break; case WJB_KEY: /* Initialize hash from parent */ + if (!stack->parent) /* should never happen */ + elog(ERROR, "error jsonb iteration"); stack->hash = stack->parent->hash; JsonbHashScalarValue(&v, &stack->hash); break; diff --git a/jsquery_extract.c b/jsquery_extract.c index 4db3041..d26efd4 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -48,6 +48,7 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) ExtractedNodeType type; JsQueryItem elem, e; + e.hint = false; check_stack_depth(); switch(jsq->type) From 5bf859ccd9b64164f3a264658048c2830c532422 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 16 Feb 2018 00:37:46 +0300 Subject: [PATCH 17/53] Handle paths without operators in indexes. --- expected/jsquery.out | 68 ++++++++++++++++++++++++++++++++++++++++++++ jsquery_extract.c | 43 ++++++++++++++++++++++++---- sql/jsquery.sql | 11 +++++++ 3 files changed, 116 insertions(+), 6 deletions(-) diff --git a/expected/jsquery.out b/expected/jsquery.out index 54b2b95..177d735 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -2165,6 +2165,13 @@ SELECT gin_debug_query_path_value('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT * (1 row) +SELECT gin_debug_query_path_value('$ = true'); + gin_debug_query_path_value +---------------------------- + $ = true , entry 0 + + +(1 row) + SELECT gin_debug_query_value_path('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5'); gin_debug_query_value_path ---------------------------- @@ -2375,6 +2382,13 @@ SELECT gin_debug_query_value_path('tags.#.term. ? ( # = "NYC").x > 0'); (1 row) +SELECT gin_debug_query_path_value('$ = true'); + gin_debug_query_path_value +---------------------------- + $ = true , entry 0 + + +(1 row) + ---table and index select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 0; count @@ -2624,6 +2638,24 @@ select count(*) from test_jsquery where v @@ '$ = false'; 2 (1 row) +select count(*) from test_jsquery where v @@ 't'; + count +------- + 10 +(1 row) + +select count(*) from test_jsquery where v @@ '$'; + count +------- + 1034 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; + count +------- + 1001 +(1 row) + select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; v ------------------- @@ -2872,6 +2904,24 @@ select count(*) from test_jsquery where v @@ '$ = false'; 2 (1 row) +select count(*) from test_jsquery where v @@ 't'; + count +------- + 10 +(1 row) + +select count(*) from test_jsquery where v @@ '$'; + count +------- + 1034 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; + count +------- + 1001 +(1 row) + explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; QUERY PLAN --------------------------------------------------------------- @@ -3165,6 +3215,24 @@ select count(*) from test_jsquery where v @@ '$ = false'; 2 (1 row) +select count(*) from test_jsquery where v @@ 't'; + count +------- + 10 +(1 row) + +select count(*) from test_jsquery where v @@ '$'; + count +------- + 1034 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; + count +------- + 950 +(1 row) + explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; QUERY PLAN --------------------------------------------------------------- diff --git a/jsquery_extract.c b/jsquery_extract.c index d26efd4..6599c1d 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -22,6 +22,7 @@ #include "jsquery.h" static ExtractedNode *recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path); +static ExtractedNode *makeAnyNode(bool not, bool indirect, PathItem *path); static int coundChildren(ExtractedNode *node, ExtractedNodeType type, bool first, bool *found); static void fillChildren(ExtractedNode *node, ExtractedNodeType type, bool first, ExtractedNode **items, int *i); static void flatternTree(ExtractedNode *node); @@ -95,7 +96,8 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) pathItem->type = iKey; pathItem->s = jsqGetString(jsq, &pathItem->len); pathItem->parent = path; - jsqGetNext(jsq, &elem); + if (!jsqGetNext(jsq, &elem)) + return makeAnyNode(not, indirect, pathItem); return recursiveExtract(&elem, not, indirect, pathItem); case jqiAny: case jqiAll: @@ -104,14 +106,16 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) pathItem = (PathItem *)palloc(sizeof(PathItem)); pathItem->type = iAny; pathItem->parent = path; - jsqGetNext(jsq, &elem); + if (!jsqGetNext(jsq, &elem)) + return makeAnyNode(not, indirect, pathItem); return recursiveExtract(&elem, not, true, pathItem); case jqiIndexArray: pathItem = (PathItem *)palloc(sizeof(PathItem)); pathItem->type = iIndexArray; pathItem->arrayIndex = jsq->arrayIndex; pathItem->parent = path; - jsqGetNext(jsq, &elem); + if (!jsqGetNext(jsq, &elem)) + return makeAnyNode(not, indirect, pathItem); return recursiveExtract(&elem, not, true, pathItem); case jqiAnyArray: case jqiAllArray: @@ -120,7 +124,8 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) pathItem = (PathItem *)palloc(sizeof(PathItem)); pathItem->type = iAnyArray; pathItem->parent = path; - jsqGetNext(jsq, &elem); + if (!jsqGetNext(jsq, &elem)) + return makeAnyNode(not, indirect, pathItem); return recursiveExtract(&elem, not, true, pathItem); case jqiAnyKey: case jqiAllKey: @@ -129,12 +134,14 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) pathItem = (PathItem *)palloc(sizeof(PathItem)); pathItem->type = iAnyKey; pathItem->parent = path; - jsqGetNext(jsq, &elem); + if (!jsqGetNext(jsq, &elem)) + return makeAnyNode(not, indirect, pathItem); return recursiveExtract(&elem, not, true, pathItem); case jqiFilter: /* ignore filter for now */ case jqiCurrent: - jsqGetNext(jsq, &elem); + if (!jsqGetNext(jsq, &elem)) + return makeAnyNode(not, indirect, path); return recursiveExtract(&elem, not, indirect, path); case jqiEqual: if (not) @@ -264,6 +271,25 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) return NULL; } +/* + * Make node for checking existence of path. + */ +static ExtractedNode * +makeAnyNode(bool not, bool indirect, PathItem *path) +{ + ExtractedNode *result; + + if (not) + return NULL; + + result = (ExtractedNode *) palloc(sizeof(ExtractedNode)); + result->type = eAny; + result->hint = false; + result->path = path; + result->indirect = indirect; + return result; +} + /* * Count number of children connected with nodes of same type. */ @@ -857,6 +883,11 @@ execRecursiveTristate(ExtractedNode *node, GinTernaryValue *check) static void debugPath(StringInfo buf, PathItem *path) { + if (!path) + { + appendStringInfoChar(buf, '$'); + return; + } if (path->parent) { debugPath(buf, path->parent); diff --git a/sql/jsquery.sql b/sql/jsquery.sql index 3450bdc..86fb40f 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -417,6 +417,7 @@ SELECT gin_debug_query_path_value('x is object'); SELECT gin_debug_query_path_value('#:(x=1) AND %:(y=1) AND *:(z=1)'); SELECT gin_debug_query_path_value('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)'); SELECT gin_debug_query_path_value('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)'); +SELECT gin_debug_query_path_value('$ = true'); SELECT gin_debug_query_value_path('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5'); SELECT gin_debug_query_value_path('NOT #(x=1) and NOT *(y=1) and NOT %(z=1) '); @@ -444,6 +445,7 @@ SELECT gin_debug_query_value_path('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT * SELECT gin_debug_query_value_path('(@# > 0 and #: = 16)'); SELECT gin_debug_query_value_path('*.@# ($ = 4 or $ = 2)'); SELECT gin_debug_query_value_path('tags.#.term. ? ( # = "NYC").x > 0'); +SELECT gin_debug_query_path_value('$ = true'); ---table and index @@ -492,6 +494,9 @@ select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'; select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'; select count(*) from test_jsquery where v @@ '$ > 2'; select count(*) from test_jsquery where v @@ '$ = false'; +select count(*) from test_jsquery where v @@ 't'; +select count(*) from test_jsquery where v @@ '$'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; select v from test_jsquery where v @@ 'array && [2,3]' order by v; @@ -538,6 +543,9 @@ select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'; select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'; select count(*) from test_jsquery where v @@ '$ > 2'; select count(*) from test_jsquery where v @@ '$ = false'; +select count(*) from test_jsquery where v @@ 't'; +select count(*) from test_jsquery where v @@ '$'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order by v; @@ -591,6 +599,9 @@ select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'; select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'; select count(*) from test_jsquery where v @@ '$ > 2'; select count(*) from test_jsquery where v @@ '$ = false'; +select count(*) from test_jsquery where v @@ 't'; +select count(*) from test_jsquery where v @@ '$'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order by v; From 8362a5e5afea9fff84a920152a9a05b452bbab92 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 16 Feb 2018 01:02:31 +0300 Subject: [PATCH 18/53] Handle filters in indexes From index perspective, filter is basically the same as AND operator. --- jsquery_extract.c | 25 ++++++++++++++++++------- sql/jsquery.sql | 12 +++++++++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/jsquery_extract.c b/jsquery_extract.c index 6599c1d..4ef3de2 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -56,12 +56,25 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) { case jqiAnd: case jqiOr: - type = ((jsq->type == jqiAnd) == not) ? eOr : eAnd; + case jqiFilter: + type = ((jsq->type == jqiAnd || jsq->type == jqiFilter) == not) ? eOr : eAnd; - jsqGetLeftArg(jsq, &elem); - leftNode = recursiveExtract(&elem, not, false, path); - jsqGetRightArg(jsq, &elem); - rightNode = recursiveExtract(&elem, not, false, path); + if (jsq->type == jqiFilter) + { + jsqGetArg(jsq, &elem); + leftNode = recursiveExtract(&elem, not, false, path); + if (jsqGetNext(jsq, &elem)) + rightNode = recursiveExtract(&elem, not, false, path); + else + rightNode = makeAnyNode(not, false, path); + } + else + { + jsqGetLeftArg(jsq, &elem); + leftNode = recursiveExtract(&elem, not, false, path); + jsqGetRightArg(jsq, &elem); + rightNode = recursiveExtract(&elem, not, false, path); + } if (!leftNode || !rightNode) { @@ -137,8 +150,6 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) if (!jsqGetNext(jsq, &elem)) return makeAnyNode(not, indirect, pathItem); return recursiveExtract(&elem, not, true, pathItem); - case jqiFilter: - /* ignore filter for now */ case jqiCurrent: if (!jsqGetNext(jsq, &elem)) return makeAnyNode(not, indirect, path); diff --git a/sql/jsquery.sql b/sql/jsquery.sql index 86fb40f..fb501b6 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -418,6 +418,8 @@ SELECT gin_debug_query_path_value('#:(x=1) AND %:(y=1) AND *:(z=1)'); SELECT gin_debug_query_path_value('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)'); SELECT gin_debug_query_path_value('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)'); SELECT gin_debug_query_path_value('$ = true'); +SELECT gin_debug_query_path_value('$ . ? (review_votes > 10) . review_rating < 7'); +SELECT gin_debug_query_path_value('similar_product_ids . ? (# = "B0002W4TL2") . $'); SELECT gin_debug_query_value_path('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5'); SELECT gin_debug_query_value_path('NOT #(x=1) and NOT *(y=1) and NOT %(z=1) '); @@ -445,7 +447,9 @@ SELECT gin_debug_query_value_path('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT * SELECT gin_debug_query_value_path('(@# > 0 and #: = 16)'); SELECT gin_debug_query_value_path('*.@# ($ = 4 or $ = 2)'); SELECT gin_debug_query_value_path('tags.#.term. ? ( # = "NYC").x > 0'); -SELECT gin_debug_query_path_value('$ = true'); +SELECT gin_debug_query_value_path('$ = true'); +SELECT gin_debug_query_value_path('$ . ? (review_votes > 10) . review_rating < 7'); +SELECT gin_debug_query_value_path('similar_product_ids . ? (# = "B0002W4TL2") . $'); ---table and index @@ -497,6 +501,8 @@ select count(*) from test_jsquery where v @@ '$ = false'; select count(*) from test_jsquery where v @@ 't'; select count(*) from test_jsquery where v @@ '$'; select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; select v from test_jsquery where v @@ 'array && [2,3]' order by v; @@ -546,6 +552,8 @@ select count(*) from test_jsquery where v @@ '$ = false'; select count(*) from test_jsquery where v @@ 't'; select count(*) from test_jsquery where v @@ '$'; select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order by v; @@ -602,6 +610,8 @@ select count(*) from test_jsquery where v @@ '$ = false'; select count(*) from test_jsquery where v @@ 't'; select count(*) from test_jsquery where v @@ '$'; select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order by v; From adc5fdfe62e23834792645832868af07fda68798 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 16 Feb 2018 01:10:14 +0300 Subject: [PATCH 19/53] Forgotten regression tests output for filters handling in indexes. --- expected/jsquery.out | 78 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/expected/jsquery.out b/expected/jsquery.out index 177d735..7a06abb 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -2172,6 +2172,22 @@ SELECT gin_debug_query_path_value('$ = true'); (1 row) +SELECT gin_debug_query_path_value('$ . ? (review_votes > 10) . review_rating < 7'); + gin_debug_query_path_value +-------------------------------- + AND + + review_rating < 7 , entry 0 + + review_votes > 10 , entry 1 + + +(1 row) + +SELECT gin_debug_query_path_value('similar_product_ids . ? (# = "B0002W4TL2") . $'); + gin_debug_query_path_value +------------------------------------------------- + similar_product_ids.# = "B0002W4TL2" , entry 0 + + +(1 row) + SELECT gin_debug_query_value_path('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5'); gin_debug_query_value_path ---------------------------- @@ -2376,19 +2392,35 @@ SELECT gin_debug_query_value_path('*.@# ($ = 4 or $ = 2)'); (1 row) SELECT gin_debug_query_value_path('tags.#.term. ? ( # = "NYC").x > 0'); - gin_debug_query_value_path ------------------------------- - tags.#.term.x > 0 , entry 0 + + gin_debug_query_value_path +---------------------------------- + tags.#.term.# = "NYC" , entry 0 + (1 row) -SELECT gin_debug_query_path_value('$ = true'); - gin_debug_query_path_value +SELECT gin_debug_query_value_path('$ = true'); + gin_debug_query_value_path ---------------------------- $ = true , entry 0 + (1 row) +SELECT gin_debug_query_value_path('$ . ? (review_votes > 10) . review_rating < 7'); + gin_debug_query_value_path +-------------------------------- + AND + + review_rating < 7 , entry 0 + + review_votes > 10 , entry 1 + + +(1 row) + +SELECT gin_debug_query_value_path('similar_product_ids . ? (# = "B0002W4TL2") . $'); + gin_debug_query_value_path +------------------------------------------------- + similar_product_ids.# = "B0002W4TL2" , entry 0 + + +(1 row) + ---table and index select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 0; count @@ -2656,6 +2688,18 @@ select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; 1001 (1 row) +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; + count +------- + 79 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; + count +------- + 3 +(1 row) + select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; v ------------------- @@ -2922,6 +2966,18 @@ select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; 1001 (1 row) +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; + count +------- + 79 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; + count +------- + 3 +(1 row) + explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; QUERY PLAN --------------------------------------------------------------- @@ -3233,6 +3289,18 @@ select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; 950 (1 row) +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; + count +------- + 79 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; + count +------- + 3 +(1 row) + explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; QUERY PLAN --------------------------------------------------------------- From 88a915687f35025a8a469bcf03bda6ab594f6630 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 16 Feb 2018 14:06:38 +0300 Subject: [PATCH 20/53] Add licese file and badge --- LICENSE | 11 +++++++++++ README.md | 1 + 2 files changed, 12 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b5411fb --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +JsQuery is released under the PostgreSQL License, a liberal Open Source license, similar to the BSD or MIT licenses. + +Copyright (c) 2014-2018, Postgres Professional +Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group +Portions Copyright (c) 1994, The Regents of the University of California + +Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies. + +IN NO EVENT SHALL POSTGRES PROFESSIONAL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF POSTGRES PROFESSIONAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +POSTGRES PROFESSIONAL SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND POSTGRES PROFESSIONAL HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. diff --git a/README.md b/README.md index 3ce8dc8..7b15ae0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Build Status](https://travis-ci.org/postgrespro/jsquery.svg?branch=master)](https://travis-ci.org/postgrespro/jsquery) [![codecov](https://codecov.io/gh/postgrespro/jsquery/branch/master/graph/badge.svg)](https://codecov.io/gh/postgrespro/jsquery) +[![GitHub license](https://img.shields.io/badge/license-PostgreSQL-blue.svg)](https://raw.githubusercontent.com/postgrespro/jsquery/master/LICENSE) JsQuery – json query language with GIN indexing support ======================================================= From 2b5d437e51d3fbd04dfb066a72117f54caada024 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Mon, 19 Feb 2018 16:10:42 +0300 Subject: [PATCH 21/53] Collect core dumps during checks and examine them for backtraces. --- travis/pg-travis-test.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 1c192ab..7bd713d 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -68,6 +68,10 @@ fi CLUSTER_PATH=$(pwd)/test_cluster $initdb_path -D $CLUSTER_PATH -U $USER -A trust +# enable core dumps and specify their path +ulimit -c unlimited -S +echo '/tmp/%e-%s-%p.core' | sudo tee /proc/sys/kernel/core_pattern + # build jsquery (using CFLAGS_SL for gcov) make USE_PGXS=1 PG_CONFIG=$config_path CFLAGS_SL="$($config_path --cflags_sl) -coverage" sudo make install USE_PGXS=1 PG_CONFIG=$config_path @@ -89,6 +93,13 @@ PGPORT=55435 PGUSER=$USER PG_CONFIG=$config_path make installcheck USE_PGXS=1 || # show diff if it exists if test -f regression.diffs; then cat regression.diffs; fi +# check core dumps if any +for corefile in $(find /tmp/ -name '*.core' 2>/dev/null) ; do + binary=$(gdb -quiet -core $corefile -batch -ex 'info auxv' | grep AT_EXECFN | perl -pe "s/^.*\"(.*)\"\$/\$1/g") + echo dumping $corefile for $binary + gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" $binary $corefile +done + #generate *.gcov files gcov *.c *.h From 60c696e75dd22688a5cac903034117c7be5338f5 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 23 Feb 2018 12:50:52 +0300 Subject: [PATCH 22/53] Run travis-ci with valgrind. --- .travis.yml | 20 ++++----- travis/pg-travis-test.sh | 89 ++++++++++++++++++++++++++++++---------- 2 files changed, 77 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2f24ce5..a406494 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,16 +20,14 @@ env: global: - LLVM_VER=4.0 matrix: - - PG_VER=10 CHECK_CODE=true - - PG_VER=10 CHECK_CODE=false - - PG_VER=9.6 CHECK_CODE=true - - PG_VER=9.6 CHECK_CODE=false - - PG_VER=9.5 CHECK_CODE=true - - PG_VER=9.5 CHECK_CODE=false - - PG_VER=9.4 CHECK_CODE=true - - PG_VER=9.4 CHECK_CODE=false + - PG_VER=10 CHECK_TYPE=normal + - PG_VER=10 CHECK_TYPE=static + - PG_VER=10 CHECK_TYPE=valgrind + - PG_VER=9.6 CHECK_TYPE=normal + - PG_VER=9.6 CHECK_TYPE=static + - PG_VER=9.5 CHECK_TYPE=normal + - PG_VER=9.5 CHECK_TYPE=static + - PG_VER=9.4 CHECK_TYPE=normal + - PG_VER=9.4 CHECK_TYPE=static script: bash ./travis/pg-travis-test.sh - -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 7bd713d..16567b3 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -4,19 +4,6 @@ set -eux sudo apt-get update - -# required packages -apt_packages="postgresql-$PG_VER postgresql-server-dev-$PG_VER postgresql-common build-essential flex bison" - -# exit code -status=0 - -# pg_config path -pg_ctl_path=/usr/lib/postgresql/$PG_VER/bin/pg_ctl -initdb_path=/usr/lib/postgresql/$PG_VER/bin/initdb -config_path=/usr/lib/postgresql/$PG_VER/bin/pg_config - - # bug: http://www.postgresql.org/message-id/20130508192711.GA9243@msgid.df7cb.de sudo update-alternatives --remove-all postmaster.1.gz @@ -26,12 +13,41 @@ sudo service postgresql stop echo 'exit 0' | sudo tee /etc/init.d/postgresql sudo chmod a+x /etc/init.d/postgresql -# install required packages -sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages +# install PostgreSQL +if [ $CHECK_TYPE = "valgrind" ]; then + # install required packages + apt_packages="build-essential libgd-dev valgrind lcov" + sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages + # grab sources from github + tag=`curl -s 'https://api.github.com/repos/postgres/postgres/git/refs/tags' | jq -r '.[] | .ref' | sed 's/^refs\/tags\///' | grep "REL_*${PG_VER/./_}_" | tail -n 1` + prefix="$HOME/pgsql-$tag" + curl "https://codeload.github.com/postgres/postgres/tar.gz/$tag" -o ~/$tag.tar.gz + # build them with valgrind support + pushd ~ + tar -xzf "$tag.tar.gz" + cd "postgres-$tag" + ./configure --enable-debug --enable-cassert --enable-coverage --prefix=$prefix + sed -i.bak "s/\/* #define USE_VALGRIND *\//#define USE_VALGRIND/g" src/include/pg_config_manual.h + make -sj4 + make -sj4 install + popd + export PATH="$prefix/bin:$PATH" +else + apt_packages="postgresql-$PG_VER postgresql-server-dev-$PG_VER postgresql-common build-essential libgd-dev" + sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages + prefix=/usr/lib/postgresql/$PG_VER +fi + +# config path +pg_ctl_path=$prefix/bin/pg_ctl +initdb_path=$prefix/bin/initdb +config_path=$prefix/bin/pg_config +# exit code +status=0 # perform code analysis if necessary -if [ $CHECK_CODE = "true" ]; then +if [ $CHECK_TYPE = "static" ]; then if [ "$CC" = "clang" ]; then sudo apt-get -y install -qq clang-$LLVM_VER @@ -72,9 +88,14 @@ $initdb_path -D $CLUSTER_PATH -U $USER -A trust ulimit -c unlimited -S echo '/tmp/%e-%s-%p.core' | sudo tee /proc/sys/kernel/core_pattern -# build jsquery (using CFLAGS_SL for gcov) -make USE_PGXS=1 PG_CONFIG=$config_path CFLAGS_SL="$($config_path --cflags_sl) -coverage" -sudo make install USE_PGXS=1 PG_CONFIG=$config_path +# build extension (using CFLAGS_SL for gcov) +if [ $CHECK_TYPE == "valgrind" ] && [ $CC = "clang" ]; then + make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path + make install USE_PGXS=1 PG_CONFIG=$config_path +else + make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path CFLAGS_SL="$($config_path --cflags_sl) -coverage" + sudo make install USE_PGXS=1 PG_CONFIG=$config_path +fi # check build status=$? @@ -85,7 +106,15 @@ sudo chown $USER /var/run/postgresql/ # start cluster 'test' echo "port = 55435" >> $CLUSTER_PATH/postgresql.conf -$pg_ctl_path -D $CLUSTER_PATH start -l postgres.log -w +if [ $CHECK_TYPE = "valgrind" ]; then + PGCTLTIMEOUT=600 \ + valgrind --leak-check=no --gen-suppressions=all \ + --suppressions=$HOME/postgres-$tag/src/tools/valgrind.supp --time-stamp=yes \ + --log-file=/tmp/pid-%p.log --trace-children=yes \ + $pg_ctl_path -D $CLUSTER_PATH start -l postgres.log -w +else + $pg_ctl_path -D $CLUSTER_PATH start -l postgres.log -w +fi # run regression tests PGPORT=55435 PGUSER=$USER PG_CONFIG=$config_path make installcheck USE_PGXS=1 || status=$? @@ -93,6 +122,17 @@ PGPORT=55435 PGUSER=$USER PG_CONFIG=$config_path make installcheck USE_PGXS=1 || # show diff if it exists if test -f regression.diffs; then cat regression.diffs; fi +# show valgrind logs if needed +if [ $CHECK_TYPE = "valgrind" ]; then + for f in ` find /tmp -name pid-*.log ` ; do + if grep -q 'Command: [^ ]*/postgres' $f && grep -q 'ERROR SUMMARY: [1-9]' $f; then + echo "========= Contents of $f" + cat $f + status=1 + fi + done +fi + # check core dumps if any for corefile in $(find /tmp/ -name '*.core' 2>/dev/null) ; do binary=$(gdb -quiet -core $corefile -batch -ex 'info auxv' | grep AT_EXECFN | perl -pe "s/^.*\"(.*)\"\$/\$1/g") @@ -100,7 +140,14 @@ for corefile in $(find /tmp/ -name '*.core' 2>/dev/null) ; do gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" $binary $corefile done +# stop cluster +$pg_ctl_path -D $CLUSTER_PATH stop -l postgres.log -w + #generate *.gcov files -gcov *.c *.h +if [ $CHECK_TYPE == "valgrind" ] && [ $CC = "clang" ]; then + bash <(curl -s https://codecov.io/bash) -x "llvm-cov gcov" +else + bash <(curl -s https://codecov.io/bash) +fi exit $status From 36e85d8303475a6fe0fba4f1960bbc8e3086aa0e Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 23 Feb 2018 12:58:35 +0300 Subject: [PATCH 23/53] Stop cluster before looking for test results. --- travis/pg-travis-test.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 16567b3..d1c0f35 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -119,6 +119,9 @@ fi # run regression tests PGPORT=55435 PGUSER=$USER PG_CONFIG=$config_path make installcheck USE_PGXS=1 || status=$? +# stop cluster +$pg_ctl_path -D $CLUSTER_PATH stop -l postgres.log -w + # show diff if it exists if test -f regression.diffs; then cat regression.diffs; fi @@ -140,9 +143,6 @@ for corefile in $(find /tmp/ -name '*.core' 2>/dev/null) ; do gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" $binary $corefile done -# stop cluster -$pg_ctl_path -D $CLUSTER_PATH stop -l postgres.log -w - #generate *.gcov files if [ $CHECK_TYPE == "valgrind" ] && [ $CC = "clang" ]; then bash <(curl -s https://codecov.io/bash) -x "llvm-cov gcov" From 0777fb6711a6e48d18b61aed330a1ca524347985 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 23 Feb 2018 17:54:00 +0300 Subject: [PATCH 24/53] Really build extension using specified compiler. --- travis/pg-travis-test.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index d1c0f35..1f8cc8d 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -89,11 +89,11 @@ ulimit -c unlimited -S echo '/tmp/%e-%s-%p.core' | sudo tee /proc/sys/kernel/core_pattern # build extension (using CFLAGS_SL for gcov) -if [ $CHECK_TYPE == "valgrind" ] && [ $CC = "clang" ]; then +if [ $CHECK_TYPE == "valgrind" ]; then make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path make install USE_PGXS=1 PG_CONFIG=$config_path else - make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path CFLAGS_SL="$($config_path --cflags_sl) -coverage" + make USE_PGXS=1 USE_ASSERT_CHECKING=1 CC=$CC PG_CONFIG=$config_path CFLAGS_SL="$($config_path --cflags_sl) -coverage" sudo make install USE_PGXS=1 PG_CONFIG=$config_path fi @@ -144,7 +144,7 @@ for corefile in $(find /tmp/ -name '*.core' 2>/dev/null) ; do done #generate *.gcov files -if [ $CHECK_TYPE == "valgrind" ] && [ $CC = "clang" ]; then +if [ $CC = "clang" ]; then bash <(curl -s https://codecov.io/bash) -x "llvm-cov gcov" else bash <(curl -s https://codecov.io/bash) From 954f6da04b1a50df0965d9fb1220a045728cf277 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 23 Feb 2018 18:24:51 +0300 Subject: [PATCH 25/53] Fix valgrind compaints. --- jsquery_extract.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/jsquery_extract.c b/jsquery_extract.c index 4ef3de2..bee9ea4 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -250,16 +250,18 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) if (jsq->type == jqiGreater || jsq->type == jqiGreaterOrEqual) { + result->bounds.leftBound = (JsQueryItem *)palloc(sizeof(JsQueryItem)); result->bounds.leftInclusive = (jsq->type == jqiGreaterOrEqual); result->bounds.rightBound = NULL; - result->bounds.leftBound = (JsQueryItem *)palloc(sizeof(JsQueryItem)); + result->bounds.rightInclusive = false; jsqGetArg(jsq, result->bounds.leftBound); } else { + result->bounds.rightBound = (JsQueryItem *)palloc(sizeof(JsQueryItem)); result->bounds.rightInclusive = (jsq->type == jqiLessOrEqual); result->bounds.leftBound = NULL; - result->bounds.rightBound = (JsQueryItem *)palloc(sizeof(JsQueryItem)); + result->bounds.leftInclusive = false; jsqGetArg(jsq, result->bounds.rightBound); } return result; @@ -699,12 +701,13 @@ makeEntries(ExtractedNode *node, MakeEntryHandler handler, Pointer extra) for (i = 0; i < node->args.count; i++) { child = node->args.items[i]; - if (!child) continue; - if (child->sClass > node->sClass && !child->forceIndex) - { - Assert(node->type != eOr); + if (!child) + continue; + /* Skip non-selective AND children */ + if (child->sClass > node->sClass && + node->type == eAnd && + !child->forceIndex) continue; - } child = makeEntries(child, handler, extra); if (child) { @@ -771,6 +774,8 @@ setSelectivityClass(ExtractedNode *node, CheckEntryHandler checkHandler, if (!child) continue; + setSelectivityClass(child, checkHandler, extra); + if (!isLogicalNodeType(child->type)) { if (child->hint == jsqNoIndex || @@ -778,8 +783,6 @@ setSelectivityClass(ExtractedNode *node, CheckEntryHandler checkHandler, continue; } - setSelectivityClass(child, checkHandler, extra); - if (child->forceIndex) node->forceIndex = true; From 8ee940914178551f8397795c01f6a389d3ede6c2 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 23 Feb 2018 22:27:17 +0300 Subject: [PATCH 26/53] Add travis output folding. --- travis/pg-travis-test.sh | 41 +++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 1f8cc8d..1096724 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -2,6 +2,8 @@ set -eux +echo -en 'travis_fold:start:pg_install\\r' && echo 'PostgreSQL installation' + sudo apt-get update # bug: http://www.postgresql.org/message-id/20130508192711.GA9243@msgid.df7cb.de @@ -46,8 +48,11 @@ config_path=$prefix/bin/pg_config # exit code status=0 +echo -en 'travis_fold:end:pg_install\\r' + # perform code analysis if necessary if [ $CHECK_TYPE = "static" ]; then + echo -en 'travis_fold:start:static_analysis\\r' && echo 'Static analysis' if [ "$CC" = "clang" ]; then sudo apt-get -y install -qq clang-$LLVM_VER @@ -55,7 +60,6 @@ if [ $CHECK_TYPE = "static" ]; then scan-build-$LLVM_VER --status-bugs \ -disable-checker deadcode.DeadStores \ make USE_PGXS=1 USE_ASSERT_CHECKING=1 PG_CONFIG=$config_path || status=$? - exit $status elif [ "$CC" = "gcc" ]; then sudo apt-get -y install -qq cppcheck @@ -71,22 +75,15 @@ if [ $CHECK_TYPE = "static" ]; then cat cppcheck.log status=1 # error fi - - exit $status fi # don't forget to "make clean" make clean USE_PGXS=1 PG_CONFIG=$config_path + echo -en 'travis_fold:end:static_analysis\\r' + exit $status fi - -# create cluster 'test' -CLUSTER_PATH=$(pwd)/test_cluster -$initdb_path -D $CLUSTER_PATH -U $USER -A trust - -# enable core dumps and specify their path -ulimit -c unlimited -S -echo '/tmp/%e-%s-%p.core' | sudo tee /proc/sys/kernel/core_pattern +echo -en 'travis_fold:start:build_extension\\r' && echo 'Build extension' # build extension (using CFLAGS_SL for gcov) if [ $CHECK_TYPE == "valgrind" ]; then @@ -101,9 +98,21 @@ fi status=$? if [ $status -ne 0 ]; then exit $status; fi +echo -en 'travis_fold:end:build_extension\\r' + +echo -en 'travis_fold:start:run_tests\\r' && echo 'Run tests' + +# enable core dumps and specify their path +ulimit -c unlimited -S +echo '/tmp/%e-%s-%p.core' | sudo tee /proc/sys/kernel/core_pattern + # set permission to write postgres locks sudo chown $USER /var/run/postgresql/ +# create cluster 'test' +CLUSTER_PATH=$(pwd)/test_cluster +$initdb_path -D $CLUSTER_PATH -U $USER -A trust + # start cluster 'test' echo "port = 55435" >> $CLUSTER_PATH/postgresql.conf if [ $CHECK_TYPE = "valgrind" ]; then @@ -122,6 +131,10 @@ PGPORT=55435 PGUSER=$USER PG_CONFIG=$config_path make installcheck USE_PGXS=1 || # stop cluster $pg_ctl_path -D $CLUSTER_PATH stop -l postgres.log -w +echo -en 'travis_fold:end:run_tests\\r' + +echo -en 'travis_fold:start:output\\r' && echo 'Check output' + # show diff if it exists if test -f regression.diffs; then cat regression.diffs; fi @@ -143,6 +156,10 @@ for corefile in $(find /tmp/ -name '*.core' 2>/dev/null) ; do gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" $binary $corefile done +echo -en 'travis_fold:end:output\\r' + +echo -en 'travis_fold:start:coverage\\r' && echo 'Coverage check' + #generate *.gcov files if [ $CC = "clang" ]; then bash <(curl -s https://codecov.io/bash) -x "llvm-cov gcov" @@ -150,4 +167,6 @@ else bash <(curl -s https://codecov.io/bash) fi +echo -en 'travis_fold:end:coverage\\r' + exit $status From 780ade6526c887da350b1cde40bdff82c1990b95 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Sat, 24 Feb 2018 00:09:17 +0300 Subject: [PATCH 27/53] Remove useless lines from travis-ci script. --- travis/pg-travis-test.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 1096724..0ba474b 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -94,10 +94,6 @@ else sudo make install USE_PGXS=1 PG_CONFIG=$config_path fi -# check build -status=$? -if [ $status -ne 0 ]; then exit $status; fi - echo -en 'travis_fold:end:build_extension\\r' echo -en 'travis_fold:start:run_tests\\r' && echo 'Run tests' From 837b8b71805be3f1f15268279827e58367552989 Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Mon, 16 Apr 2018 18:57:18 +0300 Subject: [PATCH 28/53] Change .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 8e194bc..acd374a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ .deps +/log/ +/results/ +/tmp_check/ *.so *.o jsquery_gram.c From 81e25a09d6a229a98f3596e98ca6df713855ae41 Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Tue, 17 Apr 2018 13:17:06 +0300 Subject: [PATCH 29/53] Fix compilation warnings --- jsonb_gin_ops.c | 16 ++++++++-------- jsquery.h | 8 ++++++++ jsquery_extract.c | 4 ++-- jsquery_op.c | 12 ++++++------ 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/jsonb_gin_ops.c b/jsonb_gin_ops.c index eef8a0d..32d1e92 100644 --- a/jsonb_gin_ops.c +++ b/jsonb_gin_ops.c @@ -732,7 +732,7 @@ gin_extract_jsonb_value_path_internal(Jsonb *jb, int32 *nentries, uint32 **bloom Datum gin_extract_jsonb_value_path(PG_FUNCTION_ARGS) { - Jsonb *jb = PG_GETARG_JSONB(0); + Jsonb *jb = PG_GETARG_JSONB_P(0); int32 *nentries = (int32 *) PG_GETARG_POINTER(1); PG_RETURN_POINTER(gin_extract_jsonb_value_path_internal(jb, nentries, NULL)); @@ -770,12 +770,12 @@ gin_extract_jsonb_query_value_path(PG_FUNCTION_ARGS) switch(strategy) { case JsonbContainsStrategyNumber: - jb = PG_GETARG_JSONB(0); + jb = PG_GETARG_JSONB_P(0); entries = gin_extract_jsonb_value_path_internal(jb, nentries, NULL); break; case JsonbNestedContainsStrategyNumber: - jb = PG_GETARG_JSONB(0); + jb = PG_GETARG_JSONB_P(0); entries = gin_extract_jsonb_value_path_internal(jb, nentries, &bloom); n = *nentries; @@ -867,7 +867,7 @@ gin_triconsistent_jsonb_value_path(PG_FUNCTION_ARGS) { GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0); StrategyNumber strategy = PG_GETARG_UINT16(1); - /* Jsonb *query = PG_GETARG_JSONB(2); */ + /* Jsonb *query = PG_GETARG_JSONB_P(2); */ int32 nkeys = PG_GETARG_INT32(3); Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); GinTernaryValue res = GIN_TRUE; @@ -1171,7 +1171,7 @@ gin_extract_jsonb_path_value_internal(Jsonb *jb, int32 *nentries) Datum gin_extract_jsonb_path_value(PG_FUNCTION_ARGS) { - Jsonb *jb = PG_GETARG_JSONB(0); + Jsonb *jb = PG_GETARG_JSONB_P(0); int32 *nentries = (int32 *) PG_GETARG_POINTER(1); PG_RETURN_POINTER(gin_extract_jsonb_path_value_internal(jb, nentries)); @@ -1209,7 +1209,7 @@ gin_extract_jsonb_query_path_value(PG_FUNCTION_ARGS) switch(strategy) { case JsonbContainsStrategyNumber: - jb = PG_GETARG_JSONB(0); + jb = PG_GETARG_JSONB_P(0); entries = gin_extract_jsonb_path_value_internal(jb, nentries); break; @@ -1250,7 +1250,7 @@ gin_consistent_jsonb_path_value(PG_FUNCTION_ARGS) { bool *check = (bool *) PG_GETARG_POINTER(0); StrategyNumber strategy = PG_GETARG_UINT16(1); - /* Jsonb *query = PG_GETARG_JSONB(2); */ + /* Jsonb *query = PG_GETARG_JSONB_P(2); */ int32 nkeys = PG_GETARG_INT32(3); Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); bool *recheck = (bool *) PG_GETARG_POINTER(5); @@ -1291,7 +1291,7 @@ gin_triconsistent_jsonb_path_value(PG_FUNCTION_ARGS) { GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0); StrategyNumber strategy = PG_GETARG_UINT16(1); - /* Jsonb *query = PG_GETARG_JSONB(2); */ + /* Jsonb *query = PG_GETARG_JSONB_P(2); */ int32 nkeys = PG_GETARG_INT32(3); Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); GinTernaryValue res = GIN_TRUE; diff --git a/jsquery.h b/jsquery.h index fbfc5c5..99855b0 100644 --- a/jsquery.h +++ b/jsquery.h @@ -248,4 +248,12 @@ bool queryNeedRecheck(ExtractedNode *node); bool execRecursive(ExtractedNode *node, bool *check); bool execRecursiveTristate(ExtractedNode *node, GinTernaryValue *check); +#ifndef PG_RETURN_JSONB_P +#define PG_RETURN_JSONB_P(x) PG_RETURN_JSONB(x) +#endif + +#ifndef PG_GETARG_JSONB_P +#define PG_GETARG_JSONB_P(x) PG_GETARG_JSONB(x) +#endif + #endif diff --git a/jsquery_extract.c b/jsquery_extract.c index bee9ea4..8f80b30 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -868,7 +868,7 @@ execRecursiveTristate(ExtractedNode *node, GinTernaryValue *check) res = GIN_TRUE; for (i = 0; i < node->args.count; i++) { - v = execRecursive(node->args.items[i], check); + v = execRecursive(node->args.items[i], (bool *) check); if (v == GIN_FALSE) return GIN_FALSE; else if (v == GIN_MAYBE) @@ -879,7 +879,7 @@ execRecursiveTristate(ExtractedNode *node, GinTernaryValue *check) res = GIN_FALSE; for (i = 0; i < node->args.count; i++) { - v = execRecursive(node->args.items[i], check); + v = execRecursive(node->args.items[i], (bool *) check); if (v == GIN_TRUE) return GIN_TRUE; else if (v == GIN_MAYBE) diff --git a/jsquery_op.c b/jsquery_op.c index b023de0..4c1def3 100644 --- a/jsquery_op.c +++ b/jsquery_op.c @@ -780,7 +780,7 @@ Datum jsquery_json_exec(PG_FUNCTION_ARGS) { JsQuery *jq = PG_GETARG_JSQUERY(0); - Jsonb *jb = PG_GETARG_JSONB(1); + Jsonb *jb = PG_GETARG_JSONB_P(1); bool res; JsonbValue jbv; JsQueryItem jsq; @@ -803,7 +803,7 @@ PG_FUNCTION_INFO_V1(json_jsquery_exec); Datum json_jsquery_exec(PG_FUNCTION_ARGS) { - Jsonb *jb = PG_GETARG_JSONB(0); + Jsonb *jb = PG_GETARG_JSONB_P(0); JsQuery *jq = PG_GETARG_JSQUERY(1); bool res; JsonbValue jbv; @@ -827,7 +827,7 @@ PG_FUNCTION_INFO_V1(json_jsquery_filter); Datum json_jsquery_filter(PG_FUNCTION_ARGS) { - Jsonb *jb = PG_GETARG_JSONB(0); + Jsonb *jb = PG_GETARG_JSONB_P(0); JsQuery *jq = PG_GETARG_JSQUERY(1); Jsonb *res = NULL; JsonbValue jbv; @@ -854,9 +854,9 @@ json_jsquery_filter(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(jq, 1); if (res) - PG_RETURN_JSONB(res); - else - PG_RETURN_NULL(); + PG_RETURN_JSONB_P(res); + + PG_RETURN_NULL(); } From cde2aa2a3055e13b0627d04d47c267e3879e7111 Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Tue, 17 Apr 2018 14:16:21 +0300 Subject: [PATCH 30/53] Add an error message in travis for valgrind checks --- travis/pg-travis-test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 0ba474b..0962dfb 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -21,7 +21,9 @@ if [ $CHECK_TYPE = "valgrind" ]; then apt_packages="build-essential libgd-dev valgrind lcov" sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages # grab sources from github - tag=`curl -s 'https://api.github.com/repos/postgres/postgres/git/refs/tags' | jq -r '.[] | .ref' | sed 's/^refs\/tags\///' | grep "REL_*${PG_VER/./_}_" | tail -n 1` + echo `curl -s -I 'https://api.github.com/repos/postgres/postgres/git/refs/tags'` + tag=`curl -s 'https://api.github.com/repos/postgres/postgres/git/refs/tags' | jq -r '.[].ref' | sed 's/^refs\/tags\///' | grep "REL_*${PG_VER/./_}_" | tail -n 1` + [[ -z "$tag" ]] && { echo "could not get branch name for release" ; exit 1; } prefix="$HOME/pgsql-$tag" curl "https://codeload.github.com/postgres/postgres/tar.gz/$tag" -o ~/$tag.tar.gz # build them with valgrind support From 5ec2b2281c1a25e9bb9f3c1104600db211c19a9f Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Wed, 5 Sep 2018 14:51:15 +0300 Subject: [PATCH 31/53] fix mixed calls execRecursiveTristate and execRecursive --- jsquery_extract.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jsquery_extract.c b/jsquery_extract.c index 8f80b30..1b61267 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -868,7 +868,7 @@ execRecursiveTristate(ExtractedNode *node, GinTernaryValue *check) res = GIN_TRUE; for (i = 0; i < node->args.count; i++) { - v = execRecursive(node->args.items[i], (bool *) check); + v = execRecursiveTristate(node->args.items[i], check); if (v == GIN_FALSE) return GIN_FALSE; else if (v == GIN_MAYBE) @@ -879,7 +879,7 @@ execRecursiveTristate(ExtractedNode *node, GinTernaryValue *check) res = GIN_FALSE; for (i = 0; i < node->args.count; i++) { - v = execRecursive(node->args.items[i], (bool *) check); + v = execRecursiveTristate(node->args.items[i], check); if (v == GIN_TRUE) return GIN_TRUE; else if (v == GIN_MAYBE) From e9928b862786aaaa411920d51d1df9faca06fa49 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Wed, 5 Sep 2018 15:35:22 +0300 Subject: [PATCH 32/53] Prevent misoptimization of register variable, also for consitency added jsqIterateDestroy. --- jsquery.h | 1 + jsquery_op.c | 8 +++++--- jsquery_support.c | 8 ++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/jsquery.h b/jsquery.h index 99855b0..9563944 100644 --- a/jsquery.h +++ b/jsquery.h @@ -123,6 +123,7 @@ extern int32 jsqGetIsType(JsQueryItem *v); extern char * jsqGetString(JsQueryItem *v, int32 *len); extern void jsqIterateInit(JsQueryItem *v); extern bool jsqIterateArray(JsQueryItem *v, JsQueryItem *e); +extern void jsqIterateDestroy(JsQueryItem *v); void alignStringInfoInt(StringInfo buf); diff --git a/jsquery_op.c b/jsquery_op.c index 4c1def3..e848421 100644 --- a/jsquery_op.c +++ b/jsquery_op.c @@ -273,7 +273,8 @@ executeArrayOp(JsQueryItem *jsq, int32 op, JsonbValue *jb) int32 r = 0; /* keep static analyzer quiet */ JsonbIterator *it; JsonbValue v; - JsQueryItem elem; + JsQueryItem elem; + bool res; if (JsonbType(jb) != jbvArray) return false; @@ -284,7 +285,7 @@ executeArrayOp(JsQueryItem *jsq, int32 op, JsonbValue *jb) { while(jsqIterateArray(jsq, &elem)) { - bool res = false; + res = false; it = JsonbIteratorInit(jb->val.binary.data); @@ -306,7 +307,7 @@ executeArrayOp(JsQueryItem *jsq, int32 op, JsonbValue *jb) { if (r == WJB_ELEM) { - bool res = false; + res = false; jsqIterateInit(jsq); while(jsqIterateArray(jsq, &elem)) @@ -319,6 +320,7 @@ executeArrayOp(JsQueryItem *jsq, int32 op, JsonbValue *jb) break; } } + jsqIterateDestroy(jsq); if (op == jqiContained && res == false) return false; diff --git a/jsquery_support.c b/jsquery_support.c index 8f95840..d637ccb 100644 --- a/jsquery_support.c +++ b/jsquery_support.c @@ -252,3 +252,11 @@ jsqIterateArray(JsQueryItem *v, JsQueryItem *e) } } +void +jsqIterateDestroy(JsQueryItem *v) +{ + Assert(v->type == jqiArray); + Assert(v->array.current <= v->array.current); + v->array.current++; +} + From e54c230f0bfd9e758be244733e4f4cbea6ef0641 Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Thu, 11 Oct 2018 14:27:20 +0300 Subject: [PATCH 33/53] Use palloc0 in making key to get rid of valgrind errors --- jsonb_gin_ops.c | 89 +++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/jsonb_gin_ops.c b/jsonb_gin_ops.c index 32d1e92..a9bc22c 100644 --- a/jsonb_gin_ops.c +++ b/jsonb_gin_ops.c @@ -258,51 +258,54 @@ make_gin_key(JsonbValue *v, uint32 hash) { GINKey *key; - if (v->type == jbvNull) + switch (v->type) { - key = (GINKey *)palloc(GINKEYLEN); - key->type = v->type; - SET_VARSIZE(key, GINKEYLEN); - } - else if (v->type == jbvBool) - { - key = (GINKey *)palloc(GINKEYLEN); - key->type = v->type | (v->val.boolean ? GINKeyTrue : 0); - SET_VARSIZE(key, GINKEYLEN); - } - else if (v->type == jbvArray) - { - key = (GINKey *)palloc(GINKEYLEN); - key->type = v->type; - if (v->val.array.nElems == 0) - key->type |= GINKeyEmptyArray; - SET_VARSIZE(key, GINKEYLEN); - } - else if (v->type == jbvObject) - { - key = (GINKey *)palloc(GINKEYLEN); - key->type = v->type; - SET_VARSIZE(key, GINKEYLEN); - } - else if (v->type == jbvNumeric) - { - key = (GINKey *)palloc(GINKeyLenNumeric(VARSIZE_ANY(v->val.numeric))); - key->type = v->type; - memcpy(GINKeyDataNumeric(key), v->val.numeric, VARSIZE_ANY(v->val.numeric)); - SET_VARSIZE(key, GINKeyLenNumeric(VARSIZE_ANY(v->val.numeric))); - } - else if (v->type == jbvString) - { - key = (GINKey *)palloc(GINKeyLenString); - key->type = v->type; - GINKeyDataString(key) = hash_any((unsigned char *)v->val.string.val, - v->val.string.len); - SET_VARSIZE(key, GINKeyLenString); - } - else - { - elog(ERROR, "GINKey must be scalar"); + case jbvNull: + case jbvObject: + { + key = (GINKey *)palloc(GINKEYLEN); + key->type = v->type; + SET_VARSIZE(key, GINKEYLEN); + break; + } + case jbvBool: + { + key = (GINKey *)palloc(GINKEYLEN); + key->type = v->type | (v->val.boolean ? GINKeyTrue : 0); + SET_VARSIZE(key, GINKEYLEN); + break; + } + case jbvArray: + { + key = (GINKey *)palloc(GINKEYLEN); + key->type = v->type; + if (v->val.array.nElems == 0) + key->type |= GINKeyEmptyArray; + + SET_VARSIZE(key, GINKEYLEN); + break; + } + case jbvNumeric: + { + key = (GINKey *) palloc0(GINKeyLenNumeric(VARSIZE_ANY(v->val.numeric))); + key->type = v->type; + memcpy(GINKeyDataNumeric(key), v->val.numeric, VARSIZE_ANY(v->val.numeric)); + SET_VARSIZE(key, GINKeyLenNumeric(VARSIZE_ANY(v->val.numeric))); + break; + } + case jbvString: + { + key = (GINKey *) palloc0(GINKeyLenString); + key->type = v->type; + GINKeyDataString(key) = hash_any((unsigned char *)v->val.string.val, + v->val.string.len); + SET_VARSIZE(key, GINKeyLenString); + break; + } + default: + elog(ERROR, "GINKey must be scalar"); } + key->hash = hash; return key; } From c0df98bc9ec252c3ec6a57666f62f2665c243a68 Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Thu, 11 Oct 2018 16:41:56 +0300 Subject: [PATCH 34/53] Fix travis tests --- .travis.yml | 4 +++- travis/pg-travis-test.sh | 51 +++++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index a406494..fec84a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,9 +20,11 @@ env: global: - LLVM_VER=4.0 matrix: + - PG_VER=11 CHECK_TYPE=normal + - PG_VER=11 CHECK_TYPE=static - PG_VER=10 CHECK_TYPE=normal - PG_VER=10 CHECK_TYPE=static - - PG_VER=10 CHECK_TYPE=valgrind + - PG_VER=10.5 CHECK_TYPE=valgrind - PG_VER=9.6 CHECK_TYPE=normal - PG_VER=9.6 CHECK_TYPE=static - PG_VER=9.5 CHECK_TYPE=normal diff --git a/travis/pg-travis-test.sh b/travis/pg-travis-test.sh index 0962dfb..18a393f 100755 --- a/travis/pg-travis-test.sh +++ b/travis/pg-travis-test.sh @@ -20,22 +20,45 @@ if [ $CHECK_TYPE = "valgrind" ]; then # install required packages apt_packages="build-essential libgd-dev valgrind lcov" sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages - # grab sources from github - echo `curl -s -I 'https://api.github.com/repos/postgres/postgres/git/refs/tags'` - tag=`curl -s 'https://api.github.com/repos/postgres/postgres/git/refs/tags' | jq -r '.[].ref' | sed 's/^refs\/tags\///' | grep "REL_*${PG_VER/./_}_" | tail -n 1` - [[ -z "$tag" ]] && { echo "could not get branch name for release" ; exit 1; } - prefix="$HOME/pgsql-$tag" - curl "https://codeload.github.com/postgres/postgres/tar.gz/$tag" -o ~/$tag.tar.gz - # build them with valgrind support + + set -e + pushd ~ - tar -xzf "$tag.tar.gz" - cd "postgres-$tag" - ./configure --enable-debug --enable-cassert --enable-coverage --prefix=$prefix + CUSTOM_PG_BIN=$PWD/pg_bin + CUSTOM_PG_SRC=$PWD/postgresql + + curl "https://ftp.postgresql.org/pub/source/v$PG_VER/postgresql-$PG_VER.tar.bz2" -o postgresql.tar.bz2 + mkdir $CUSTOM_PG_SRC + + tar \ + --extract \ + --file postgresql.tar.bz2 \ + --directory $CUSTOM_PG_SRC \ + --strip-components 1 + + cd $CUSTOM_PG_SRC + + # enable Valgrind support sed -i.bak "s/\/* #define USE_VALGRIND *\//#define USE_VALGRIND/g" src/include/pg_config_manual.h - make -sj4 - make -sj4 install + + # enable additional options + ./configure \ + CFLAGS='-Og -ggdb3 -fno-omit-frame-pointer' \ + --enable-cassert \ + --enable-coverage \ + --prefix=$CUSTOM_PG_BIN \ + --quiet + + # build & install PG + time make -s -j4 && make -s install + + # override default PostgreSQL instance + export PATH=$CUSTOM_PG_BIN/bin:$PATH + export LD_LIBRARY_PATH=$CUSTOM_PG_BIN/lib + popd - export PATH="$prefix/bin:$PATH" + set +e + prefix=$CUSTOM_PG_BIN else apt_packages="postgresql-$PG_VER postgresql-server-dev-$PG_VER postgresql-common build-essential libgd-dev" sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $apt_packages @@ -116,7 +139,7 @@ echo "port = 55435" >> $CLUSTER_PATH/postgresql.conf if [ $CHECK_TYPE = "valgrind" ]; then PGCTLTIMEOUT=600 \ valgrind --leak-check=no --gen-suppressions=all \ - --suppressions=$HOME/postgres-$tag/src/tools/valgrind.supp --time-stamp=yes \ + --suppressions=$CUSTOM_PG_SRC/src/tools/valgrind.supp --time-stamp=yes \ --log-file=/tmp/pid-%p.log --trace-children=yes \ $pg_ctl_path -D $CLUSTER_PATH start -l postgres.log -w else From 656ddcc75b20d00870572377150de2c5b933d6bd Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Thu, 11 Oct 2018 16:49:00 +0300 Subject: [PATCH 35/53] Bump version to 1.1.1 --- META.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/META.json b/META.json index b8cd2a8..56d37f6 100644 --- a/META.json +++ b/META.json @@ -2,7 +2,7 @@ "name": "JsQuery", "abstract": "JSON Query Language with GIN indexing support", "description": "JsQuery provides additional functionality for JSONB, such as a simple and effective way to search in nested objects and arrays, and more comparison operators with index support. It does this by implementing a specialized search syntax, the @@ operator, and the jsquery type for search strings.", - "version": "1.0.1", + "version": "1.1.1", "maintainer": [ "Teodor Sigaev ", "Alexander Korotkov ", @@ -14,10 +14,10 @@ "prereqs": { "runtime": { "requires": { - "PostgreSQL": "9.4.0" + "PostgreSQL": "9.4" }, "recommends": { - "PostgreSQL": "9.6.5" + "PostgreSQL": "10.0" } } }, @@ -25,7 +25,7 @@ "jsquery": { "file": "sql/jsquery.sql", "docfile": "README.md", - "version": "1.0.1", + "version": "1.1.1", "abstract": "JSON query language with GIN indexing support" } }, @@ -42,7 +42,7 @@ }, "generated_by": "Josh Berkus", "meta-spec": { - "version": "1.0.0", + "version": "1.1.1", "url": "http://pgxn.org/meta/spec.txt" }, "tags": [ From 0b6deb317cad0bfb084cf6599c19af3609eeaa69 Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Thu, 1 Nov 2018 18:41:00 +0300 Subject: [PATCH 36/53] Fix 'greater than' operator for jsquery type --- jsquery--1.1.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsquery--1.1.sql b/jsquery--1.1.sql index bec1279..ad5fcdb 100644 --- a/jsquery--1.1.sql +++ b/jsquery--1.1.sql @@ -178,7 +178,7 @@ CREATE OPERATOR >= ( CREATE OPERATOR > ( LEFTARG = jsquery, RIGHTARG = jsquery, - PROCEDURE = jsquery_ge, + PROCEDURE = jsquery_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, From acb20a6c49d237bab817965b1d3b49536735d16d Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Thu, 1 Nov 2018 19:57:28 +0300 Subject: [PATCH 37/53] Fix 'not equal' parameter --- jsquery--1.1.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsquery--1.1.sql b/jsquery--1.1.sql index ad5fcdb..d10076a 100644 --- a/jsquery--1.1.sql +++ b/jsquery--1.1.sql @@ -158,7 +158,7 @@ CREATE OPERATOR = ( CREATE OPERATOR <> ( LEFTARG = jsquery, RIGHTARG = jsquery, - PROCEDURE = jsquery_eq, + PROCEDURE = jsquery_ne, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, From 3e820d9104484ceae0ceb859bd1bf4e0004f0256 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Tue, 22 Jan 2019 17:10:58 +0300 Subject: [PATCH 38/53] Fix wrong assert: it was always true --- jsquery_support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsquery_support.c b/jsquery_support.c index d637ccb..08a805d 100644 --- a/jsquery_support.c +++ b/jsquery_support.c @@ -256,7 +256,7 @@ void jsqIterateDestroy(JsQueryItem *v) { Assert(v->type == jqiArray); - Assert(v->array.current <= v->array.current); + Assert(v->array.current <= v->array.nelems); v->array.current++; } From b96ef6d7205e20fa508dd5c73761adf380b73643 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Wed, 18 Sep 2019 18:42:47 +0300 Subject: [PATCH 39/53] Support for 12 pgsql. Only test was changed: 12 version has new operator jsonb @@ jsonpath which conflicts (in tests) with jsonb @@ jsquery. So, add explicit cast in tests. --- expected/jsquery.out | 558 +++++++++++++++++++-------------------- sql/jsquery.sql | 614 +++++++++++++++++++++---------------------- 2 files changed, 586 insertions(+), 586 deletions(-) diff --git a/expected/jsquery.out b/expected/jsquery.out index 7a06abb..6767433 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -530,343 +530,343 @@ select 'a.b.#10203.* > 4'::jsquery; "a"."b".#10203.* > 4 (1 row) -select '{"a": {"b": null}}'::jsonb @@ 'a.b = 1'; +select '{"a": {"b": null}}'::jsonb @@ 'a.b = 1'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": null}}'::jsonb @@ 'a.b = null'; +select '{"a": {"b": null}}'::jsonb @@ 'a.b = null'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": null}}'::jsonb @@ 'a.b = false'; +select '{"a": {"b": null}}'::jsonb @@ 'a.b = false'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": false}}'::jsonb @@ 'a.b = false'; +select '{"a": {"b": false}}'::jsonb @@ 'a.b = false'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": false}}'::jsonb @@ 'a.b = true'; +select '{"a": {"b": false}}'::jsonb @@ 'a.b = true'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": true}}'::jsonb @@ 'a.b = true'; +select '{"a": {"b": true}}'::jsonb @@ 'a.b = true'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 1'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 1'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 1'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 1'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 1'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 1'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 1'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 1'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 1'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 1'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 2'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 2'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 2'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 2'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 2'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 2'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 2'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 2'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 2'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 2'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 0'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 0'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 0'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 0'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 0'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 0'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 0'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 0'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 0'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 0'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ '*.b > 0'; +select '{"a": {"b": 1}}'::jsonb @@ '*.b > 0'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ '*.b > 0'; +select '{"a": {"b": 1}}'::jsonb @@ '*.b > 0'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.* > 0'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.* > 0'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1}}'::jsonb @@ 'a.* > 0'; +select '{"a": {"b": 1}}'::jsonb @@ 'a.* > 0'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 1 ]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 1 ]'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b @> [ 1 ]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b @> [ 1 ]'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b <@ [ 1 ]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b <@ [ 1 ]'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b @> [ 1,2,3,4 ]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b @> [ 1,2,3,4 ]'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b <@ [ 1,2,3,4 ]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b <@ [ 1,2,3,4 ]'::jsquery; ?column? ---------- t (1 row) -select '[{"a": 2}, {"a": 3}]'::jsonb @@ '*.a = 4'; +select '[{"a": 2}, {"a": 3}]'::jsonb @@ '*.a = 4'::jsquery; ?column? ---------- f (1 row) -select '[{"a": 2}, {"a": 3}]'::jsonb @@ '*.a = 3'; +select '[{"a": 2}, {"a": 3}]'::jsonb @@ '*.a = 3'::jsquery; ?column? ---------- t (1 row) -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.a = 4'; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.a = 4'::jsquery; ?column? ---------- f (1 row) -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.a = 4'; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.a = 4'::jsquery; ?column? ---------- t (1 row) -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 1 OR a=3)'; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 1 OR a=3)'::jsquery; ?column? ---------- t (1 row) -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 OR a=1)'; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 OR a=1)'::jsquery; ?column? ---------- t (1 row) -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 and a=1)'; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 and a=1)'::jsquery; ?column? ---------- f (1 row) -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 and a=2)' as "false"; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 and a=2)'::jsquery as "false"; false ------- f (1 row) -select '[{"a": 2, "b":3}, {"a": 3, "b": 1}]'::jsonb @@ '#(b = 1 and a=3)'; +select '[{"a": 2, "b":3}, {"a": 3, "b": 1}]'::jsonb @@ '#(b = 1 and a=3)'::jsquery; ?column? ---------- t (1 row) -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.a.a = 4'; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.a.a = 4'::jsquery; ?column? ---------- t (1 row) -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.a.a = 4'; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.a.a = 4'::jsquery; ?column? ---------- t (1 row) -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.#.a.a = 4'; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.#.a.a = 4'::jsquery; ?column? ---------- t (1 row) -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.*.a.a = 4'; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.*.a.a = 4'::jsquery; ?column? ---------- t (1 row) -select '{"a": 1}'::jsonb @@ 'a in (0,1,2)'; +select '{"a": 1}'::jsonb @@ 'a in (0,1,2)'::jsquery; ?column? ---------- t (1 row) -select '{"a": 1}'::jsonb @@ 'a in (0,2)'; +select '{"a": 1}'::jsonb @@ 'a in (0,2)'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#=2'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#=2'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 5 ]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 5 ]'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a=*'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a=*'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b=*'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b=*'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.c=*'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.c=*'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b = [1,2,3]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b = [1,2,3]'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# = [1,2,3]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# = [1,2,3]'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b && [1,2,3]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b && [1,2,3]'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# && [1,2,3]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# && [1,2,3]'::jsquery; ?column? ---------- f (1 row) -select 'asd.# = 3'::jsquery & 'zzz = true' | 'xxx.# = zero'; +select 'asd.# = 3'::jsquery & 'zzz = true' | 'xxx.# = zero'::jsquery; ?column? ------------------------------------------------------ (("asd".# = 3 AND "zzz" = true) OR "xxx".# = "zero") (1 row) -select !'asd.# = 3'::jsquery & 'zzz = true' | !'xxx.# = zero'; +select !'asd.# = 3'::jsquery & 'zzz = true' | !'xxx.# = zero'::jsquery; ?column? ------------------------------------------------------------------ (((NOT "asd".# = 3) AND "zzz" = true) OR (NOT "xxx".# = "zero")) (1 row) -select !'asd.#3.f = 3'::jsquery & 'zzz = true' | !'xxx.# = zero'; +select !'asd.#3.f = 3'::jsquery & 'zzz = true' | !'xxx.# = zero'::jsquery; ?column? ----------------------------------------------------------------------- (((NOT "asd".#3."f" = 3) AND "zzz" = true) OR (NOT "xxx".# = "zero")) @@ -890,175 +890,175 @@ select '{"x":[0,1,1,2]}'::jsonb @@ 'x @> [1,0,3]'::jsquery; f (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 2 ]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 2 ]'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b($ && [ 2 ])'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b($ && [ 2 ])'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.$.b && [ 2 ]'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.$.b && [ 2 ]'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.$.b ($ && [ 2 ])'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.$.b ($ && [ 2 ])'::jsquery; ?column? ---------- t (1 row) -select '[1,2,3]'::jsonb @@ '# && [2]'; +select '[1,2,3]'::jsonb @@ '# && [2]'::jsquery; ?column? ---------- f (1 row) -select '[1,2,3]'::jsonb @@ '#($ && [2])'; +select '[1,2,3]'::jsonb @@ '#($ && [2])'::jsquery; ?column? ---------- f (1 row) -select '[1,2,3]'::jsonb @@ '$ && [2]'; +select '[1,2,3]'::jsonb @@ '$ && [2]'::jsquery; ?column? ---------- t (1 row) -select '[1,2,3]'::jsonb @@ '$ ($ && [2])'; +select '[1,2,3]'::jsonb @@ '$ ($ && [2])'::jsquery; ?column? ---------- t (1 row) -select '[1,2,3]'::jsonb @@ '$ = 2'; +select '[1,2,3]'::jsonb @@ '$ = 2'::jsquery; ?column? ---------- f (1 row) -select '[1,2,3]'::jsonb @@ '# = 2'; +select '[1,2,3]'::jsonb @@ '# = 2'::jsquery; ?column? ---------- t (1 row) -select '[1,2,3]'::jsonb @@ '#.$ = 2'; +select '[1,2,3]'::jsonb @@ '#.$ = 2'::jsquery; ?column? ---------- t (1 row) -select '[1,2,3]'::jsonb @@ '#($ = 2)'; +select '[1,2,3]'::jsonb @@ '#($ = 2)'::jsquery; ?column? ---------- t (1 row) -select '[3,4]'::jsonb @@ '#($ > 2 and $ < 5)'; +select '[3,4]'::jsonb @@ '#($ > 2 and $ < 5)'::jsquery; ?column? ---------- t (1 row) -select '[3,4]'::jsonb @@ '# > 2 and # < 5'; +select '[3,4]'::jsonb @@ '# > 2 and # < 5'::jsquery; ?column? ---------- t (1 row) -select '[1,6]'::jsonb @@ '#($ > 2 and $ < 5)'; +select '[1,6]'::jsonb @@ '#($ > 2 and $ < 5)'::jsquery; ?column? ---------- f (1 row) -select '[1,6]'::jsonb @@ '# > 2 and # < 5'; +select '[1,6]'::jsonb @@ '# > 2 and # < 5'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%.b=3'; +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%.b=3'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ 'a.%=3'; +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ 'a.%=3'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%.%="hey"'; +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%.%="hey"'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%="hey"'; +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%="hey"'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%=[5,6]'; +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%=[5,6]'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#1 = 2'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#1 = 2'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#2 = 2'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#2 = 2'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#3 = 2'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#3 = 2'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#1.x = 2'; +select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#1.x = 2'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#2.x = 2'; +select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#2.x = 2'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#3.x = 2'; +select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#3.x = 2'::jsquery; ?column? ---------- f (1 row) -select '"XXX"'::jsonb @@ '$="XXX"'; +select '"XXX"'::jsonb @@ '$="XXX"'::jsquery; ?column? ---------- t (1 row) -select '"XXX"'::jsonb @@ '#.$="XXX"'; +select '"XXX"'::jsonb @@ '#.$="XXX"'::jsquery; ?column? ---------- f @@ -1071,19 +1071,19 @@ select 'a\t = "dollar \u0024 character"'::jsquery; "a\t" = "dollar $ character" (1 row) -select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar \u0024 character"'; +select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar \u0024 character"'::jsquery; ?column? ---------- t (1 row) -select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar $ character"'; +select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar $ character"'::jsquery; ?column? ---------- t (1 row) -select '{ "a": "dollar $ character" }'::jsonb @@ '* = "dollar \u0024 character"'; +select '{ "a": "dollar $ character" }'::jsonb @@ '* = "dollar \u0024 character"'::jsquery; ?column? ---------- t @@ -1471,157 +1471,157 @@ select 'a.$.? (b>0 and x.*= 0 ).c.k'::jsquery; "a".$. ?(("b" > 0 AND "x".* = 0)) ."c"."k" (1 row) -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a < 0) (b=20)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a < 0) (b=20)'::jsquery; ?column? ---------- f (1 row) -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 0) (b=20)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 0) (b=20)'::jsquery; ?column? ---------- t (1 row) -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 1) (b=20)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 1) (b=20)'::jsquery; ?column? ---------- t (1 row) -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 2) (b=20)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 2) (b=20)'::jsquery; ?column? ---------- f (1 row) -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 3) (b=20)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 3) (b=20)'::jsquery; ?column? ---------- f (1 row) -select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#.a'; +select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#.a'::jsquery; ?column? ---------- [1, 2] (1 row) -select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#. ?(a > 1). b'; +select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#. ?(a > 1). b'::jsquery; ?column? ---------- [20] (1 row) -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '# . ?(a > 1)'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '# . ?(a > 1)'::jsquery; ?column? ---------------------------------------- [{"a": 2, "b": 20}, {"a": 3, "b": 30}] (1 row) -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '%'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '%'::jsquery; ?column? ---------- (1 row) -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '%'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '%'::jsquery; ?column? ----------- [1, 2, 3] (1 row) -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 )'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 )'::jsquery; ?column? ---------- [3] (1 row) -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 ).$'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 ).$'::jsquery; ?column? ---------- [3] (1 row) -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( % > 2 )'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( % > 2 )'::jsquery; ?column? ---------------------------- [{"a": 1, "b": 2, "c": 3}] (1 row) -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 0 )'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 0 )'::jsquery; ?column? ---------------------------- [{"a": 1, "b": 2, "c": 3}] (1 row) -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 2 )'; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 2 )'::jsquery; ?column? ---------- (1 row) -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '#'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '#'::jsquery; ?column? ----------------------------------------------------------- [{"a": 1, "b": 10}, {"a": 2, "b": 20}, {"a": 3, "b": 30}] (1 row) -select '[1,2,3]'::jsonb ~~ '#'; +select '[1,2,3]'::jsonb ~~ '#'::jsquery; ?column? ----------- [1, 2, 3] (1 row) -select '[1,2,3]'::jsonb ~~ '#. ?($ > 2)'; +select '[1,2,3]'::jsonb ~~ '#. ?($ > 2)'::jsquery; ?column? ---------- [3] (1 row) -select '[1,2,3]'::jsonb ~~ '#. ?($ > 2).$'; +select '[1,2,3]'::jsonb ~~ '#. ?($ > 2).$'::jsquery; ?column? ---------- [3] (1 row) -select '[1,2,3]'::jsonb ~~ ' ?(#.$ > 2).$'; +select '[1,2,3]'::jsonb ~~ ' ?(#.$ > 2).$'::jsquery; ?column? ------------- [[1, 2, 3]] (1 row) -select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 2).$'; +select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 2).$'::jsquery; ?column? ---------- (1 row) -select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 0).$'; +select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 0).$'::jsquery; ?column? ------------- [[1, 2, 3]] (1 row) -select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '*.?(c >0)'; +select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '*.?(c >0)'::jsquery; ?column? ------------ [{"c": 1}] (1 row) -select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '?(*.c >0)'; +select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '?(*.c >0)'::jsquery; ?column? -------------------------- [{"a": {"b": {"c": 1}}}] (1 row) -select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term.#. ? ( $ = "NYC")'; +select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term.#. ? ( $ = "NYC")'::jsquery; ?column? ---------- ["NYC"] (1 row) -select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term. ? ( # = "NYC")'; +select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term. ? ( # = "NYC")'::jsquery; ?column? ------------------ [["NYC", "CYN"]] @@ -1856,133 +1856,133 @@ select '[16]' @@ '(@# > 0 and #: = 16)'::jsquery; t (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b or b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b or b.d'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c or b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c or b.d'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.d'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.c'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.c'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b and b.d'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.d'::jsquery; ?column? ---------- t (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.b'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.b'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g and b.d'::jsquery; ?column? ---------- f (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.d'::jsquery; ?column? ---------- [1, 3] (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.c'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.c'::jsquery; ?column? ---------- (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.d or b.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.d or b.c)'::jsquery; ?column? ---------- [1, 3] (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.c or b.d)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.c or b.d)'::jsquery; ?column? ---------- [1, 3] (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and a.c and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and a.c and b.d'::jsquery; ?column? ----------- [1, 2, 3] (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.b or a.c) and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.b or a.c) and b.d'::jsquery; ?column? ---------- [1, 3] (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.c) and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.c) and b.d'::jsquery; ?column? ---------- [2, 3] (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.g) and b.d'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.g) and b.d'::jsquery; ?column? ---------- (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b or (b.d or b.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b or (b.d or b.c)'::jsquery; ?column? ---------- [1] (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b or a.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b or a.c)'::jsquery; ?column? ---------- [3] (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b and a.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b and a.c)'::jsquery; ?column? ---------- [3] (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.f or (a.b and a.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.f or (a.b and a.c)'::jsquery; ?column? ---------- [1, 2] (1 row) -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'::jsquery; ?column? ----------- [3, 1, 2] (1 row) -select '{"a": {"b": [6,5,4], "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'; +select '{"a": {"b": [6,5,4], "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'::jsquery; ?column? ------------------- [3, [6, 5, 4], 2] @@ -2465,249 +2465,249 @@ select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 16 8 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; count ------- 654 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'::jsquery; count ------- 13 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'::jsquery; count ------- 985 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'::jsquery; count ------- 16 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'::jsquery; count ------- 988 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16' AND - v @@ 'review_helpful_votes < 20'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16'::jsquery AND + v @@ 'review_helpful_votes < 20'::jsquery; count ------- 8 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'::jsquery; count ------- 8 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'::jsquery; count ------- 8 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '; +select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'::jsquery; count ------- 4 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'; +select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'::jsquery; count ------- 54 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'; +select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ 'customer_id = null'; +select count(*) from test_jsquery where v @@ 'customer_id = null'::jsquery; count ------- 1 (1 row) -select count(*) from test_jsquery where v @@ 'review_votes = true'; +select count(*) from test_jsquery where v @@ 'review_votes = true'::jsquery; count ------- 1 (1 row) -select count(*) from test_jsquery where v @@ 'product_group = false'; +select count(*) from test_jsquery where v @@ 'product_group = false'::jsquery; count ------- 1 (1 row) -select count(*) from test_jsquery where v @@ 't = *'; +select count(*) from test_jsquery where v @@ 't = *'::jsquery; count ------- 10 (1 row) -select count(*) from test_jsquery where v @@ 't is boolean'; +select count(*) from test_jsquery where v @@ 't is boolean'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is string'; +select count(*) from test_jsquery where v @@ 't is string'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is numeric'; +select count(*) from test_jsquery where v @@ 't is numeric'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is array'; +select count(*) from test_jsquery where v @@ 't is array'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is object'; +select count(*) from test_jsquery where v @@ 't is object'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ '$ is boolean'; +select count(*) from test_jsquery where v @@ '$ is boolean'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ '$ is string'; +select count(*) from test_jsquery where v @@ '$ is string'::jsquery; count ------- 4 (1 row) -select count(*) from test_jsquery where v @@ '$ is numeric'; +select count(*) from test_jsquery where v @@ '$ is numeric'::jsquery; count ------- 5 (1 row) -select count(*) from test_jsquery where v @@ '$ is array'; +select count(*) from test_jsquery where v @@ '$ is array'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ '$ is object'; +select count(*) from test_jsquery where v @@ '$ is object'::jsquery; count ------- 1017 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'::jsquery; count ------- 51 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'::jsquery; count ------- 1001 (1 row) -select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'; +select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery; count ------- 40 (1 row) -select count(*) from test_jsquery where v @@ '$ > 2'; +select count(*) from test_jsquery where v @@ '$ > 2'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ '$ = false'; +select count(*) from test_jsquery where v @@ '$ = false'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't'; +select count(*) from test_jsquery where v @@ 't'::jsquery; count ------- 10 (1 row) -select count(*) from test_jsquery where v @@ '$'; +select count(*) from test_jsquery where v @@ '$'::jsquery; count ------- 1034 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'::jsquery; count ------- 1001 (1 row) -select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'::jsquery; count ------- 79 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'::jsquery; count ------- 3 (1 row) -select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; +select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; v ------------------- {"array": [2]} {"array": [2, 3]} (2 rows) -select v from test_jsquery where v @@ 'array && [2,3]' order by v; +select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; v ---------------------- {"array": [2]} @@ -2717,7 +2717,7 @@ select v from test_jsquery where v @@ 'array && [2,3]' order by v; {"array": [3, 4, 5]} (5 rows) -select v from test_jsquery where v @@ 'array @> [2,3]' order by v; +select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; v ---------------------- {"array": [2, 3]} @@ -2725,7 +2725,7 @@ select v from test_jsquery where v @@ 'array @> [2,3]' order by v; {"array": [2, 3, 4]} (3 rows) -select v from test_jsquery where v @@ 'array = [2,3]' order by v; +select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; v ------------------- {"array": [2, 3]} @@ -2733,7 +2733,7 @@ select v from test_jsquery where v @@ 'array = [2,3]' order by v; create index t_idx on test_jsquery using gin (v jsonb_value_path_ops); set enable_seqscan = off; -explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'; +explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; QUERY PLAN ------------------------------------------------------------------------ Aggregate @@ -2743,242 +2743,242 @@ explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful Index Cond: (v @@ '"review_helpful_votes" > 0'::jsquery) (5 rows) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; count ------- 654 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'::jsquery; count ------- 13 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'::jsquery; count ------- 985 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'::jsquery; count ------- 16 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'::jsquery; count ------- 988 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16' AND - v @@ 'review_helpful_votes < 20'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16'::jsquery AND + v @@ 'review_helpful_votes < 20'::jsquery; count ------- 8 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'::jsquery; count ------- 8 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'::jsquery; count ------- 8 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '; +select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'::jsquery; count ------- 4 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'; +select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'::jsquery; count ------- 54 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'; +select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ 'customer_id = null'; +select count(*) from test_jsquery where v @@ 'customer_id = null'::jsquery; count ------- 1 (1 row) -select count(*) from test_jsquery where v @@ 'review_votes = true'; +select count(*) from test_jsquery where v @@ 'review_votes = true'::jsquery; count ------- 1 (1 row) -select count(*) from test_jsquery where v @@ 'product_group = false'; +select count(*) from test_jsquery where v @@ 'product_group = false'::jsquery; count ------- 1 (1 row) -select count(*) from test_jsquery where v @@ 't = *'; +select count(*) from test_jsquery where v @@ 't = *'::jsquery; count ------- 10 (1 row) -select count(*) from test_jsquery where v @@ 't is boolean'; +select count(*) from test_jsquery where v @@ 't is boolean'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is string'; +select count(*) from test_jsquery where v @@ 't is string'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is numeric'; +select count(*) from test_jsquery where v @@ 't is numeric'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is array'; +select count(*) from test_jsquery where v @@ 't is array'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is object'; +select count(*) from test_jsquery where v @@ 't is object'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ '$ is boolean'; +select count(*) from test_jsquery where v @@ '$ is boolean'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ '$ is string'; +select count(*) from test_jsquery where v @@ '$ is string'::jsquery; count ------- 4 (1 row) -select count(*) from test_jsquery where v @@ '$ is numeric'; +select count(*) from test_jsquery where v @@ '$ is numeric'::jsquery; count ------- 5 (1 row) -select count(*) from test_jsquery where v @@ '$ is array'; +select count(*) from test_jsquery where v @@ '$ is array'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ '$ is object'; +select count(*) from test_jsquery where v @@ '$ is object'::jsquery; count ------- 1017 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'::jsquery; count ------- 51 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'::jsquery; count ------- 1001 (1 row) -select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'; +select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ '$ > 2'; +select count(*) from test_jsquery where v @@ '$ > 2'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ '$ = false'; +select count(*) from test_jsquery where v @@ '$ = false'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't'; +select count(*) from test_jsquery where v @@ 't'::jsquery; count ------- 10 (1 row) -select count(*) from test_jsquery where v @@ '$'; +select count(*) from test_jsquery where v @@ '$'::jsquery; count ------- 1034 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'::jsquery; count ------- 1001 (1 row) -select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'::jsquery; count ------- 79 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'::jsquery; count ------- 3 (1 row) -explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; +explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; QUERY PLAN --------------------------------------------------------------- Sort @@ -2989,7 +2989,7 @@ explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order Index Cond: (v @@ '"array" <@ [2, 3]'::jsquery) (6 rows) -explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order by v; +explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; QUERY PLAN --------------------------------------------------------------- Sort @@ -3000,7 +3000,7 @@ explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order Index Cond: (v @@ '"array" && [2, 3]'::jsquery) (6 rows) -explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]' order by v; +explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; QUERY PLAN --------------------------------------------------------------- Sort @@ -3011,7 +3011,7 @@ explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]' order Index Cond: (v @@ '"array" @> [2, 3]'::jsquery) (6 rows) -explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]' order by v; +explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; QUERY PLAN -------------------------------------------------------------- Sort @@ -3022,14 +3022,14 @@ explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]' order Index Cond: (v @@ '"array" = [2, 3]'::jsquery) (6 rows) -select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; +select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; v ------------------- {"array": [2]} {"array": [2, 3]} (2 rows) -select v from test_jsquery where v @@ 'array && [2,3]' order by v; +select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; v ---------------------- {"array": [2]} @@ -3039,7 +3039,7 @@ select v from test_jsquery where v @@ 'array && [2,3]' order by v; {"array": [3, 4, 5]} (5 rows) -select v from test_jsquery where v @@ 'array @> [2,3]' order by v; +select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; v ---------------------- {"array": [2, 3]} @@ -3047,7 +3047,7 @@ select v from test_jsquery where v @@ 'array @> [2,3]' order by v; {"array": [2, 3, 4]} (3 rows) -select v from test_jsquery where v @@ 'array = [2,3]' order by v; +select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; v ------------------- {"array": [2, 3]} @@ -3056,7 +3056,7 @@ select v from test_jsquery where v @@ 'array = [2,3]' order by v; drop index t_idx; create index t_idx on test_jsquery using gin (v jsonb_path_value_ops); set enable_seqscan = off; -explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'; +explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; QUERY PLAN ------------------------------------------------------------------------ Aggregate @@ -3066,242 +3066,242 @@ explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful Index Cond: (v @@ '"review_helpful_votes" > 0'::jsquery) (5 rows) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; count ------- 654 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'::jsquery; count ------- 13 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'::jsquery; count ------- 985 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'::jsquery; count ------- 16 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'::jsquery; count ------- 988 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16' AND - v @@ 'review_helpful_votes < 20'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16'::jsquery AND + v @@ 'review_helpful_votes < 20'::jsquery; count ------- 8 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'::jsquery; count ------- 8 (1 row) -select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'; +select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'::jsquery; count ------- 8 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '; +select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'::jsquery; count ------- 4 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'; +select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'::jsquery; count ------- 54 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'; +select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ 'customer_id = null'; +select count(*) from test_jsquery where v @@ 'customer_id = null'::jsquery; count ------- 1 (1 row) -select count(*) from test_jsquery where v @@ 'review_votes = true'; +select count(*) from test_jsquery where v @@ 'review_votes = true'::jsquery; count ------- 1 (1 row) -select count(*) from test_jsquery where v @@ 'product_group = false'; +select count(*) from test_jsquery where v @@ 'product_group = false'::jsquery; count ------- 1 (1 row) -select count(*) from test_jsquery where v @@ 't = *'; +select count(*) from test_jsquery where v @@ 't = *'::jsquery; count ------- 10 (1 row) -select count(*) from test_jsquery where v @@ 't is boolean'; +select count(*) from test_jsquery where v @@ 't is boolean'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is string'; +select count(*) from test_jsquery where v @@ 't is string'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is numeric'; +select count(*) from test_jsquery where v @@ 't is numeric'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is array'; +select count(*) from test_jsquery where v @@ 't is array'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't is object'; +select count(*) from test_jsquery where v @@ 't is object'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ '$ is boolean'; +select count(*) from test_jsquery where v @@ '$ is boolean'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ '$ is string'; +select count(*) from test_jsquery where v @@ '$ is string'::jsquery; count ------- 4 (1 row) -select count(*) from test_jsquery where v @@ '$ is numeric'; +select count(*) from test_jsquery where v @@ '$ is numeric'::jsquery; count ------- 5 (1 row) -select count(*) from test_jsquery where v @@ '$ is array'; +select count(*) from test_jsquery where v @@ '$ is array'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ '$ is object'; +select count(*) from test_jsquery where v @@ '$ is object'::jsquery; count ------- 1017 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'::jsquery; count ------- 51 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'::jsquery; count ------- 1001 (1 row) -select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'; +select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery; count ------- 7 (1 row) -select count(*) from test_jsquery where v @@ '$ > 2'; +select count(*) from test_jsquery where v @@ '$ > 2'::jsquery; count ------- 3 (1 row) -select count(*) from test_jsquery where v @@ '$ = false'; +select count(*) from test_jsquery where v @@ '$ = false'::jsquery; count ------- 2 (1 row) -select count(*) from test_jsquery where v @@ 't'; +select count(*) from test_jsquery where v @@ 't'::jsquery; count ------- 10 (1 row) -select count(*) from test_jsquery where v @@ '$'; +select count(*) from test_jsquery where v @@ '$'::jsquery; count ------- 1034 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'::jsquery; count ------- 950 (1 row) -select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'::jsquery; count ------- 79 (1 row) -select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'::jsquery; count ------- 3 (1 row) -explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; +explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; QUERY PLAN --------------------------------------------------------------- Sort @@ -3312,7 +3312,7 @@ explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order Index Cond: (v @@ '"array" <@ [2, 3]'::jsquery) (6 rows) -explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order by v; +explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; QUERY PLAN --------------------------------------------------------------- Sort @@ -3323,7 +3323,7 @@ explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order Index Cond: (v @@ '"array" && [2, 3]'::jsquery) (6 rows) -explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]' order by v; +explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; QUERY PLAN --------------------------------------------------------------- Sort @@ -3334,7 +3334,7 @@ explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]' order Index Cond: (v @@ '"array" @> [2, 3]'::jsquery) (6 rows) -explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]' order by v; +explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; QUERY PLAN -------------------------------------------------------------- Sort @@ -3345,14 +3345,14 @@ explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]' order Index Cond: (v @@ '"array" = [2, 3]'::jsquery) (6 rows) -select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; +select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; v ------------------- {"array": [2]} {"array": [2, 3]} (2 rows) -select v from test_jsquery where v @@ 'array && [2,3]' order by v; +select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; v ---------------------- {"array": [2]} @@ -3362,7 +3362,7 @@ select v from test_jsquery where v @@ 'array && [2,3]' order by v; {"array": [3, 4, 5]} (5 rows) -select v from test_jsquery where v @@ 'array @> [2,3]' order by v; +select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; v ---------------------- {"array": [2, 3]} @@ -3370,7 +3370,7 @@ select v from test_jsquery where v @@ 'array @> [2,3]' order by v; {"array": [2, 3, 4]} (3 rows) -select v from test_jsquery where v @@ 'array = [2,3]' order by v; +select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; v ------------------- {"array": [2, 3]} diff --git a/sql/jsquery.sql b/sql/jsquery.sql index fb501b6..0b50dbe 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -105,124 +105,124 @@ select 'is.not < 1'::jsquery; select 'a.b.#4 > 4'::jsquery; select 'a.b.#10203.* > 4'::jsquery; -select '{"a": {"b": null}}'::jsonb @@ 'a.b = 1'; -select '{"a": {"b": null}}'::jsonb @@ 'a.b = null'; -select '{"a": {"b": null}}'::jsonb @@ 'a.b = false'; -select '{"a": {"b": false}}'::jsonb @@ 'a.b = false'; -select '{"a": {"b": false}}'::jsonb @@ 'a.b = true'; -select '{"a": {"b": true}}'::jsonb @@ 'a.b = true'; - - -select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 1'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 1'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 1'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 1'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 1'; - -select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 2'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 2'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 2'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 2'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 2'; - -select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 0'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 0'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 0'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 0'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 0'; - -select '{"a": {"b": 1}}'::jsonb @@ '*.b > 0'; -select '{"a": {"b": 1}}'::jsonb @@ '*.b > 0'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.* > 0'; -select '{"a": {"b": 1}}'::jsonb @@ 'a.* > 0'; - -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 1 ]'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b @> [ 1 ]'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b <@ [ 1 ]'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b @> [ 1,2,3,4 ]'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b <@ [ 1,2,3,4 ]'; - -select '[{"a": 2}, {"a": 3}]'::jsonb @@ '*.a = 4'; -select '[{"a": 2}, {"a": 3}]'::jsonb @@ '*.a = 3'; - -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.a = 4'; -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.a = 4'; - -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 1 OR a=3)'; -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 OR a=1)'; -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 and a=1)'; -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 and a=2)' as "false"; -select '[{"a": 2, "b":3}, {"a": 3, "b": 1}]'::jsonb @@ '#(b = 1 and a=3)'; - -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.a.a = 4'; -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.a.a = 4'; -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.#.a.a = 4'; -select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.*.a.a = 4'; - -select '{"a": 1}'::jsonb @@ 'a in (0,1,2)'; -select '{"a": 1}'::jsonb @@ 'a in (0,2)'; - -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#=2'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 5 ]'; - -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a=*'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b=*'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.c=*'; - -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b = [1,2,3]'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# = [1,2,3]'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b && [1,2,3]'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# && [1,2,3]'; - -select 'asd.# = 3'::jsquery & 'zzz = true' | 'xxx.# = zero'; -select !'asd.# = 3'::jsquery & 'zzz = true' | !'xxx.# = zero'; -select !'asd.#3.f = 3'::jsquery & 'zzz = true' | !'xxx.# = zero'; +select '{"a": {"b": null}}'::jsonb @@ 'a.b = 1'::jsquery; +select '{"a": {"b": null}}'::jsonb @@ 'a.b = null'::jsquery; +select '{"a": {"b": null}}'::jsonb @@ 'a.b = false'::jsquery; +select '{"a": {"b": false}}'::jsonb @@ 'a.b = false'::jsquery; +select '{"a": {"b": false}}'::jsonb @@ 'a.b = true'::jsquery; +select '{"a": {"b": true}}'::jsonb @@ 'a.b = true'::jsquery; + + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 1'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 1'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 1'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 1'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 1'::jsquery; + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 2'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 2'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 2'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 2'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 2'::jsquery; + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 0'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 0'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 0'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 0'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 0'::jsquery; + +select '{"a": {"b": 1}}'::jsonb @@ '*.b > 0'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ '*.b > 0'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.* > 0'::jsquery; +select '{"a": {"b": 1}}'::jsonb @@ 'a.* > 0'::jsquery; + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 1 ]'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b @> [ 1 ]'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b <@ [ 1 ]'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b @> [ 1,2,3,4 ]'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b <@ [ 1,2,3,4 ]'::jsquery; + +select '[{"a": 2}, {"a": 3}]'::jsonb @@ '*.a = 4'::jsquery; +select '[{"a": 2}, {"a": 3}]'::jsonb @@ '*.a = 3'::jsquery; + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.a = 4'::jsquery; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.a = 4'::jsquery; + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 1 OR a=3)'::jsquery; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 OR a=1)'::jsquery; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 and a=1)'::jsquery; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 and a=2)'::jsquery as "false"; +select '[{"a": 2, "b":3}, {"a": 3, "b": 1}]'::jsonb @@ '#(b = 1 and a=3)'::jsquery; + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.a.a = 4'::jsquery; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.a.a = 4'::jsquery; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.#.a.a = 4'::jsquery; +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.*.a.a = 4'::jsquery; + +select '{"a": 1}'::jsonb @@ 'a in (0,1,2)'::jsquery; +select '{"a": 1}'::jsonb @@ 'a in (0,2)'::jsquery; + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#=2'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 5 ]'::jsquery; + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a=*'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b=*'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.c=*'::jsquery; + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b = [1,2,3]'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# = [1,2,3]'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b && [1,2,3]'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# && [1,2,3]'::jsquery; + +select 'asd.# = 3'::jsquery & 'zzz = true' | 'xxx.# = zero'::jsquery; +select !'asd.# = 3'::jsquery & 'zzz = true' | !'xxx.# = zero'::jsquery; +select !'asd.#3.f = 3'::jsquery & 'zzz = true' | !'xxx.# = zero'::jsquery; select '{"x":[0,1,1,2]}'::jsonb @@ 'x @> [1,0]'::jsquery; select '{"x":[0,1,1,2]}'::jsonb @@ 'x @> [1,0,1]'::jsquery; select '{"x":[0,1,1,2]}'::jsonb @@ 'x @> [1,0,3]'::jsquery; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 2 ]'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b($ && [ 2 ])'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.$.b && [ 2 ]'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.$.b ($ && [ 2 ])'; - -select '[1,2,3]'::jsonb @@ '# && [2]'; -select '[1,2,3]'::jsonb @@ '#($ && [2])'; -select '[1,2,3]'::jsonb @@ '$ && [2]'; -select '[1,2,3]'::jsonb @@ '$ ($ && [2])'; -select '[1,2,3]'::jsonb @@ '$ = 2'; -select '[1,2,3]'::jsonb @@ '# = 2'; -select '[1,2,3]'::jsonb @@ '#.$ = 2'; -select '[1,2,3]'::jsonb @@ '#($ = 2)'; - -select '[3,4]'::jsonb @@ '#($ > 2 and $ < 5)'; -select '[3,4]'::jsonb @@ '# > 2 and # < 5'; -select '[1,6]'::jsonb @@ '#($ > 2 and $ < 5)'; -select '[1,6]'::jsonb @@ '# > 2 and # < 5'; - -select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%.b=3'; -select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ 'a.%=3'; -select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%.%="hey"'; -select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%="hey"'; -select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%=[5,6]'; - -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#1 = 2'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#2 = 2'; -select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#3 = 2'; -select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#1.x = 2'; -select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#2.x = 2'; -select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#3.x = 2'; - -select '"XXX"'::jsonb @@ '$="XXX"'; -select '"XXX"'::jsonb @@ '#.$="XXX"'; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 2 ]'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b($ && [ 2 ])'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.$.b && [ 2 ]'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.$.b ($ && [ 2 ])'::jsquery; + +select '[1,2,3]'::jsonb @@ '# && [2]'::jsquery; +select '[1,2,3]'::jsonb @@ '#($ && [2])'::jsquery; +select '[1,2,3]'::jsonb @@ '$ && [2]'::jsquery; +select '[1,2,3]'::jsonb @@ '$ ($ && [2])'::jsquery; +select '[1,2,3]'::jsonb @@ '$ = 2'::jsquery; +select '[1,2,3]'::jsonb @@ '# = 2'::jsquery; +select '[1,2,3]'::jsonb @@ '#.$ = 2'::jsquery; +select '[1,2,3]'::jsonb @@ '#($ = 2)'::jsquery; + +select '[3,4]'::jsonb @@ '#($ > 2 and $ < 5)'::jsquery; +select '[3,4]'::jsonb @@ '# > 2 and # < 5'::jsquery; +select '[1,6]'::jsonb @@ '#($ > 2 and $ < 5)'::jsquery; +select '[1,6]'::jsonb @@ '# > 2 and # < 5'::jsquery; + +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%.b=3'::jsquery; +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ 'a.%=3'::jsquery; +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%.%="hey"'::jsquery; +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%="hey"'::jsquery; +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%=[5,6]'::jsquery; + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#1 = 2'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#2 = 2'::jsquery; +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#3 = 2'::jsquery; +select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#1.x = 2'::jsquery; +select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#2.x = 2'::jsquery; +select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#3.x = 2'::jsquery; + +select '"XXX"'::jsonb @@ '$="XXX"'::jsquery; +select '"XXX"'::jsonb @@ '#.$="XXX"'::jsquery; --Unicode select 'a\t = "dollar \u0024 character"'::jsquery; -select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar \u0024 character"'; -select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar $ character"'; -select '{ "a": "dollar $ character" }'::jsonb @@ '* = "dollar \u0024 character"'; +select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar \u0024 character"'::jsquery; +select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar $ character"'::jsquery; +select '{ "a": "dollar $ character" }'::jsonb @@ '* = "dollar \u0024 character"'::jsquery; select 'a\r = "\n\""'::jsquery; select 'a\r = "\u0000"'::jsquery; select 'a\r = \u0000'::jsquery; @@ -301,32 +301,32 @@ select '?( not b>0). x'::jsquery; select 'a.?(b>0 and x= 0 ) .c'::jsquery; select 'a.$. ?(b>0 and x= 0 ) . c.k'::jsquery; select 'a.$.? (b>0 and x.*= 0 ).c.k'::jsquery; -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a < 0) (b=20)'; -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 0) (b=20)'; -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 1) (b=20)'; -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 2) (b=20)'; -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 3) (b=20)'; -select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#.a'; -select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#. ?(a > 1). b'; -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '# . ?(a > 1)'; -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '%'; -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '%'; -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 )'; -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 ).$'; -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( % > 2 )'; -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 0 )'; -select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 2 )'; -select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '#'; -select '[1,2,3]'::jsonb ~~ '#'; -select '[1,2,3]'::jsonb ~~ '#. ?($ > 2)'; -select '[1,2,3]'::jsonb ~~ '#. ?($ > 2).$'; -select '[1,2,3]'::jsonb ~~ ' ?(#.$ > 2).$'; -select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 2).$'; -select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 0).$'; -select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '*.?(c >0)'; -select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '?(*.c >0)'; -select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term.#. ? ( $ = "NYC")'; -select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term. ? ( # = "NYC")'; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a < 0) (b=20)'::jsquery; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 0) (b=20)'::jsquery; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 1) (b=20)'::jsquery; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 2) (b=20)'::jsquery; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 3) (b=20)'::jsquery; +select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#.a'::jsquery; +select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#. ?(a > 1). b'::jsquery; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '# . ?(a > 1)'::jsquery; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '%'::jsquery; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '%'::jsquery; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 )'::jsquery; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 ).$'::jsquery; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( % > 2 )'::jsquery; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 0 )'::jsquery; +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 2 )'::jsquery; +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '#'::jsquery; +select '[1,2,3]'::jsonb ~~ '#'::jsquery; +select '[1,2,3]'::jsonb ~~ '#. ?($ > 2)'::jsquery; +select '[1,2,3]'::jsonb ~~ '#. ?($ > 2).$'::jsquery; +select '[1,2,3]'::jsonb ~~ ' ?(#.$ > 2).$'::jsquery; +select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 2).$'::jsquery; +select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 0).$'::jsquery; +select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '*.?(c >0)'::jsquery; +select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '?(*.c >0)'::jsquery; +select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term.#. ? ( $ = "NYC")'::jsquery; +select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term. ? ( # = "NYC")'::jsquery; --ALL select 'a.*: = 4'::jsquery; @@ -369,29 +369,29 @@ SELECT 'test.# IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,2 select '[]' @@ '(@# > 0 and #: = 16)'::jsquery; select '[16]' @@ '(@# > 0 and #: = 16)'::jsquery; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b or b.d'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c or b.d'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.d'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.c'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b and b.d'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.d'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.b'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g and b.d'; - -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.d'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.c'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.d or b.c)'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.c or b.d)'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and a.c and b.d'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.b or a.c) and b.d'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.c) and b.d'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.g) and b.d'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b or (b.d or b.c)'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b or a.c)'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b and a.c)'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.f or (a.b and a.c)'; -select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'; -select '{"a": {"b": [6,5,4], "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b or b.d'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c or b.d'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.d'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.c'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b and b.d'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.d'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.b'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g and b.d'::jsquery; + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.d'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.c'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.d or b.c)'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.c or b.d)'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and a.c and b.d'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.b or a.c) and b.d'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.c) and b.d'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.g) and b.d'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b or (b.d or b.c)'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b or a.c)'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b and a.c)'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.f or (a.b and a.c)'::jsquery; +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'::jsquery; +select '{"a": {"b": [6,5,4], "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'::jsquery; --extract entries for index scan @@ -463,164 +463,164 @@ select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 16 (v->>'review_helpful_votes')::int4 < 20; -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16' AND - v @@ 'review_helpful_votes < 20'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'; -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'; -select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '; -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'; -select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'; -select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'; -select count(*) from test_jsquery where v @@ 'customer_id = null'; -select count(*) from test_jsquery where v @@ 'review_votes = true'; -select count(*) from test_jsquery where v @@ 'product_group = false'; -select count(*) from test_jsquery where v @@ 't = *'; -select count(*) from test_jsquery where v @@ 't is boolean'; -select count(*) from test_jsquery where v @@ 't is string'; -select count(*) from test_jsquery where v @@ 't is numeric'; -select count(*) from test_jsquery where v @@ 't is array'; -select count(*) from test_jsquery where v @@ 't is object'; -select count(*) from test_jsquery where v @@ '$ is boolean'; -select count(*) from test_jsquery where v @@ '$ is string'; -select count(*) from test_jsquery where v @@ '$ is numeric'; -select count(*) from test_jsquery where v @@ '$ is array'; -select count(*) from test_jsquery where v @@ '$ is object'; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'; -select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'; -select count(*) from test_jsquery where v @@ '$ > 2'; -select count(*) from test_jsquery where v @@ '$ = false'; -select count(*) from test_jsquery where v @@ 't'; -select count(*) from test_jsquery where v @@ '$'; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; -select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; -select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; - -select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; -select v from test_jsquery where v @@ 'array && [2,3]' order by v; -select v from test_jsquery where v @@ 'array @> [2,3]' order by v; -select v from test_jsquery where v @@ 'array = [2,3]' order by v; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16'::jsquery AND + v @@ 'review_helpful_votes < 20'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'::jsquery; +select count(*) from test_jsquery where v @@ 'customer_id = null'::jsquery; +select count(*) from test_jsquery where v @@ 'review_votes = true'::jsquery; +select count(*) from test_jsquery where v @@ 'product_group = false'::jsquery; +select count(*) from test_jsquery where v @@ 't = *'::jsquery; +select count(*) from test_jsquery where v @@ 't is boolean'::jsquery; +select count(*) from test_jsquery where v @@ 't is string'::jsquery; +select count(*) from test_jsquery where v @@ 't is numeric'::jsquery; +select count(*) from test_jsquery where v @@ 't is array'::jsquery; +select count(*) from test_jsquery where v @@ 't is object'::jsquery; +select count(*) from test_jsquery where v @@ '$ is boolean'::jsquery; +select count(*) from test_jsquery where v @@ '$ is string'::jsquery; +select count(*) from test_jsquery where v @@ '$ is numeric'::jsquery; +select count(*) from test_jsquery where v @@ '$ is array'::jsquery; +select count(*) from test_jsquery where v @@ '$ is object'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'::jsquery; +select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery; +select count(*) from test_jsquery where v @@ '$ > 2'::jsquery; +select count(*) from test_jsquery where v @@ '$ = false'::jsquery; +select count(*) from test_jsquery where v @@ 't'::jsquery; +select count(*) from test_jsquery where v @@ '$'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'::jsquery; +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'::jsquery; + +select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; +select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; +select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; +select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; create index t_idx on test_jsquery using gin (v jsonb_value_path_ops); set enable_seqscan = off; -explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'; - -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16' AND - v @@ 'review_helpful_votes < 20'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'; -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'; -select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '; -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'; -select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'; -select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'; -select count(*) from test_jsquery where v @@ 'customer_id = null'; -select count(*) from test_jsquery where v @@ 'review_votes = true'; -select count(*) from test_jsquery where v @@ 'product_group = false'; -select count(*) from test_jsquery where v @@ 't = *'; -select count(*) from test_jsquery where v @@ 't is boolean'; -select count(*) from test_jsquery where v @@ 't is string'; -select count(*) from test_jsquery where v @@ 't is numeric'; -select count(*) from test_jsquery where v @@ 't is array'; -select count(*) from test_jsquery where v @@ 't is object'; -select count(*) from test_jsquery where v @@ '$ is boolean'; -select count(*) from test_jsquery where v @@ '$ is string'; -select count(*) from test_jsquery where v @@ '$ is numeric'; -select count(*) from test_jsquery where v @@ '$ is array'; -select count(*) from test_jsquery where v @@ '$ is object'; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'; -select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'; -select count(*) from test_jsquery where v @@ '$ > 2'; -select count(*) from test_jsquery where v @@ '$ = false'; -select count(*) from test_jsquery where v @@ 't'; -select count(*) from test_jsquery where v @@ '$'; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; -select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; -select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; - -explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; -explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order by v; -explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]' order by v; -explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]' order by v; - -select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; -select v from test_jsquery where v @@ 'array && [2,3]' order by v; -select v from test_jsquery where v @@ 'array @> [2,3]' order by v; -select v from test_jsquery where v @@ 'array = [2,3]' order by v; +explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16'::jsquery AND + v @@ 'review_helpful_votes < 20'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'::jsquery; +select count(*) from test_jsquery where v @@ 'customer_id = null'::jsquery; +select count(*) from test_jsquery where v @@ 'review_votes = true'::jsquery; +select count(*) from test_jsquery where v @@ 'product_group = false'::jsquery; +select count(*) from test_jsquery where v @@ 't = *'::jsquery; +select count(*) from test_jsquery where v @@ 't is boolean'::jsquery; +select count(*) from test_jsquery where v @@ 't is string'::jsquery; +select count(*) from test_jsquery where v @@ 't is numeric'::jsquery; +select count(*) from test_jsquery where v @@ 't is array'::jsquery; +select count(*) from test_jsquery where v @@ 't is object'::jsquery; +select count(*) from test_jsquery where v @@ '$ is boolean'::jsquery; +select count(*) from test_jsquery where v @@ '$ is string'::jsquery; +select count(*) from test_jsquery where v @@ '$ is numeric'::jsquery; +select count(*) from test_jsquery where v @@ '$ is array'::jsquery; +select count(*) from test_jsquery where v @@ '$ is object'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'::jsquery; +select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery; +select count(*) from test_jsquery where v @@ '$ > 2'::jsquery; +select count(*) from test_jsquery where v @@ '$ = false'::jsquery; +select count(*) from test_jsquery where v @@ 't'::jsquery; +select count(*) from test_jsquery where v @@ '$'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'::jsquery; +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'::jsquery; + +explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; +explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; +explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; +explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; + +select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; +select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; +select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; +select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; drop index t_idx; create index t_idx on test_jsquery using gin (v jsonb_path_value_ops); set enable_seqscan = off; -explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'; - -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16' AND - v @@ 'review_helpful_votes < 20'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'; -select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'; -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'; -select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '; -select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'; -select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'; -select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'; -select count(*) from test_jsquery where v @@ 'customer_id = null'; -select count(*) from test_jsquery where v @@ 'review_votes = true'; -select count(*) from test_jsquery where v @@ 'product_group = false'; -select count(*) from test_jsquery where v @@ 't = *'; -select count(*) from test_jsquery where v @@ 't is boolean'; -select count(*) from test_jsquery where v @@ 't is string'; -select count(*) from test_jsquery where v @@ 't is numeric'; -select count(*) from test_jsquery where v @@ 't is array'; -select count(*) from test_jsquery where v @@ 't is object'; -select count(*) from test_jsquery where v @@ '$ is boolean'; -select count(*) from test_jsquery where v @@ '$ is string'; -select count(*) from test_jsquery where v @@ '$ is numeric'; -select count(*) from test_jsquery where v @@ '$ is array'; -select count(*) from test_jsquery where v @@ '$ is object'; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'; -select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'; -select count(*) from test_jsquery where v @@ '$ > 2'; -select count(*) from test_jsquery where v @@ '$ = false'; -select count(*) from test_jsquery where v @@ 't'; -select count(*) from test_jsquery where v @@ '$'; -select count(*) from test_jsquery where v @@ 'similar_product_ids.#'; -select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'; -select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'; - -explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; -explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order by v; -explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]' order by v; -explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]' order by v; - -select v from test_jsquery where v @@ 'array <@ [2,3]' order by v; -select v from test_jsquery where v @@ 'array && [2,3]' order by v; -select v from test_jsquery where v @@ 'array @> [2,3]' order by v; -select v from test_jsquery where v @@ 'array = [2,3]' order by v; +explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16'::jsquery AND + v @@ 'review_helpful_votes < 20'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'::jsquery; +select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'::jsquery; +select count(*) from test_jsquery where v @@ 'customer_id = null'::jsquery; +select count(*) from test_jsquery where v @@ 'review_votes = true'::jsquery; +select count(*) from test_jsquery where v @@ 'product_group = false'::jsquery; +select count(*) from test_jsquery where v @@ 't = *'::jsquery; +select count(*) from test_jsquery where v @@ 't is boolean'::jsquery; +select count(*) from test_jsquery where v @@ 't is string'::jsquery; +select count(*) from test_jsquery where v @@ 't is numeric'::jsquery; +select count(*) from test_jsquery where v @@ 't is array'::jsquery; +select count(*) from test_jsquery where v @@ 't is object'::jsquery; +select count(*) from test_jsquery where v @@ '$ is boolean'::jsquery; +select count(*) from test_jsquery where v @@ '$ is string'::jsquery; +select count(*) from test_jsquery where v @@ '$ is numeric'::jsquery; +select count(*) from test_jsquery where v @@ '$ is array'::jsquery; +select count(*) from test_jsquery where v @@ '$ is object'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'::jsquery; +select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery; +select count(*) from test_jsquery where v @@ '$ > 2'::jsquery; +select count(*) from test_jsquery where v @@ '$ = false'::jsquery; +select count(*) from test_jsquery where v @@ 't'::jsquery; +select count(*) from test_jsquery where v @@ '$'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'::jsquery; +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'::jsquery; +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'::jsquery; + +explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; +explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; +explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; +explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; + +select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; +select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; +select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; +select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; RESET enable_seqscan; From aa15dd10ee31a931d07338e213b595c82e776cfa Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Thu, 18 Jun 2020 12:41:35 +0300 Subject: [PATCH 40/53] fix some svace warnigs --- jsquery_io.c | 1 + jsquery_support.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/jsquery_io.c b/jsquery_io.c index 4bee263..2e4c328 100644 --- a/jsquery_io.c +++ b/jsquery_io.c @@ -117,6 +117,7 @@ flattenJsQueryParseItem(StringInfo buf, JsQueryParseItem *item, bool onlyCurrent case jqiIndexArray: appendBinaryStringInfo(buf, (char*)&item->arrayIndex, sizeof(item->arrayIndex)); + /* FALLTHROUGH */ /* keep svace quiet */ case jqiAny: case jqiAnyArray: case jqiAnyKey: diff --git a/jsquery_support.c b/jsquery_support.c index 08a805d..278e561 100644 --- a/jsquery_support.c +++ b/jsquery_support.c @@ -209,7 +209,7 @@ jsqGetNumeric(JsQueryItem *v) int32 jsqGetIsType(JsQueryItem *v) { - Assert(v->type = jqiIs); + Assert(v->type == jqiIs); return (int32)*v->value.data; } From 09f67b2f668cae407b836aa87a401c5b4e4cf0f7 Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Tue, 11 Aug 2020 12:45:00 +0300 Subject: [PATCH 41/53] Added alternate test result for compilation with new flex Flex 2.6.4 and above changed format of some generated error mesages which appear in our test results. So we added alternate test result to accomodate th thm them --- expected/jsquery_1.out | 3379 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 3379 insertions(+) create mode 100644 expected/jsquery_1.out diff --git a/expected/jsquery_1.out b/expected/jsquery_1.out new file mode 100644 index 0000000..a265cc9 --- /dev/null +++ b/expected/jsquery_1.out @@ -0,0 +1,3379 @@ +CREATE EXTENSION jsquery; +set escape_string_warning=off; +set standard_conforming_strings=on; +CREATE TABLE test_jsquery (v jsonb); +\copy test_jsquery from 'data/test_jsquery.data' +select 'asd.zzz = 13'::jsquery; + jsquery +------------------ + "asd"."zzz" = 13 +(1 row) + +select 'asd.zzz < 13'::jsquery; + jsquery +------------------ + "asd"."zzz" < 13 +(1 row) + +select 'asd(zzz < 13)'::jsquery; + jsquery +------------------ + "asd"."zzz" < 13 +(1 row) + +select 'asd(zzz < 13 AND x = true)'::jsquery; + jsquery +---------------------------------- + "asd"("zzz" < 13 AND "x" = true) +(1 row) + +select 'asd(zzz < 13 AND x = "true")'::jsquery; + jsquery +------------------------------------ + "asd"("zzz" < 13 AND "x" = "true") +(1 row) + +select 'asd(zzz < 13 AND x.zxc = "true")'::jsquery; + jsquery +------------------------------------------ + "asd"("zzz" < 13 AND "x"."zxc" = "true") +(1 row) + +select 'asd(zzz < 13 OR #.zxc = "true" /* test */)'::jsquery; + jsquery +--------------------------------------- + "asd"("zzz" < 13 OR #."zxc" = "true") +(1 row) + +select 'asd(* < 13 AND /* ttt */ #.zxc = "true")'::jsquery; + jsquery +------------------------------------ + "asd"(* < 13 AND #."zxc" = "true") +(1 row) + +select '(* < 13 AND #.zxc = "true")'::jsquery; + jsquery +------------------------------- + (* < 13 AND #."zxc" = "true") +(1 row) + +select '* < 13 AND #.zxc/* t2 */ = "true"'::jsquery; + jsquery +------------------------------- + (* < 13 AND #."zxc" = "true") +(1 row) + +select '* < 13 AND #.zxc"x" = "true"'::jsquery; +ERROR: bad jsquery representation +LINE 1: select '* < 13 AND #.zxc"x" = "true"'::jsquery; + ^ +DETAIL: syntax error, unexpected STRING_P, expecting end of file at or near """ +select 'a < 1'::jsquery; + jsquery +--------- + "a" < 1 +(1 row) + +select 'a < -1'::jsquery; + jsquery +---------- + "a" < -1 +(1 row) + +select 'a < +1'::jsquery; + jsquery +--------- + "a" < 1 +(1 row) + +select 'a < .1'::jsquery; + jsquery +----------- + "a" < 0.1 +(1 row) + +select 'a < -.1'::jsquery; + jsquery +------------ + "a" < -0.1 +(1 row) + +select 'a < +.1'::jsquery; + jsquery +----------- + "a" < 0.1 +(1 row) + +select 'a < 0.1'::jsquery; + jsquery +----------- + "a" < 0.1 +(1 row) + +select 'a < -0.1'::jsquery; + jsquery +------------ + "a" < -0.1 +(1 row) + +select 'a < +0.1'::jsquery; + jsquery +----------- + "a" < 0.1 +(1 row) + +select 'a < 10.1'::jsquery; + jsquery +------------ + "a" < 10.1 +(1 row) + +select 'a < -10.1'::jsquery; + jsquery +------------- + "a" < -10.1 +(1 row) + +select 'a < +10.1'::jsquery; + jsquery +------------ + "a" < 10.1 +(1 row) + +select 'a < 1e1'::jsquery; + jsquery +---------- + "a" < 10 +(1 row) + +select 'a < -1e1'::jsquery; + jsquery +----------- + "a" < -10 +(1 row) + +select 'a < +1e1'::jsquery; + jsquery +---------- + "a" < 10 +(1 row) + +select 'a < .1e1'::jsquery; + jsquery +--------- + "a" < 1 +(1 row) + +select 'a < -.1e1'::jsquery; + jsquery +---------- + "a" < -1 +(1 row) + +select 'a < +.1e1'::jsquery; + jsquery +--------- + "a" < 1 +(1 row) + +select 'a < 0.1e1'::jsquery; + jsquery +--------- + "a" < 1 +(1 row) + +select 'a < -0.1e1'::jsquery; + jsquery +---------- + "a" < -1 +(1 row) + +select 'a < +0.1e1'::jsquery; + jsquery +--------- + "a" < 1 +(1 row) + +select 'a < 10.1e1'::jsquery; + jsquery +----------- + "a" < 101 +(1 row) + +select 'a < -10.1e1'::jsquery; + jsquery +------------ + "a" < -101 +(1 row) + +select 'a < +10.1e1'::jsquery; + jsquery +----------- + "a" < 101 +(1 row) + +select 'a < 1e-1'::jsquery; + jsquery +----------- + "a" < 0.1 +(1 row) + +select 'a < -1e-1'::jsquery; + jsquery +------------ + "a" < -0.1 +(1 row) + +select 'a < +1e-1'::jsquery; + jsquery +----------- + "a" < 0.1 +(1 row) + +select 'a < .1e-1'::jsquery; + jsquery +------------ + "a" < 0.01 +(1 row) + +select 'a < -.1e-1'::jsquery; + jsquery +------------- + "a" < -0.01 +(1 row) + +select 'a < +.1e-1'::jsquery; + jsquery +------------ + "a" < 0.01 +(1 row) + +select 'a < 0.1e-1'::jsquery; + jsquery +------------ + "a" < 0.01 +(1 row) + +select 'a < -0.1e-1'::jsquery; + jsquery +------------- + "a" < -0.01 +(1 row) + +select 'a < +0.1e-1'::jsquery; + jsquery +------------ + "a" < 0.01 +(1 row) + +select 'a < 10.1e-1'::jsquery; + jsquery +------------ + "a" < 1.01 +(1 row) + +select 'a < -10.1e-1'::jsquery; + jsquery +------------- + "a" < -1.01 +(1 row) + +select 'a < +10.1e-1'::jsquery; + jsquery +------------ + "a" < 1.01 +(1 row) + +select 'a < 1e+1'::jsquery; + jsquery +---------- + "a" < 10 +(1 row) + +select 'a < -1e+1'::jsquery; + jsquery +----------- + "a" < -10 +(1 row) + +select 'a < +1e+1'::jsquery; + jsquery +---------- + "a" < 10 +(1 row) + +select 'a < .1e+1'::jsquery; + jsquery +--------- + "a" < 1 +(1 row) + +select 'a < -.1e+1'::jsquery; + jsquery +---------- + "a" < -1 +(1 row) + +select 'a < +.1e+1'::jsquery; + jsquery +--------- + "a" < 1 +(1 row) + +select 'a < 0.1e+1'::jsquery; + jsquery +--------- + "a" < 1 +(1 row) + +select 'a < -0.1e+1'::jsquery; + jsquery +---------- + "a" < -1 +(1 row) + +select 'a < +0.1e+1'::jsquery; + jsquery +--------- + "a" < 1 +(1 row) + +select 'a < 10.1e+1'::jsquery; + jsquery +----------- + "a" < 101 +(1 row) + +select 'a < -10.1e+1'::jsquery; + jsquery +------------ + "a" < -101 +(1 row) + +select 'a < +10.1e+1'::jsquery; + jsquery +----------- + "a" < 101 +(1 row) + +select 'a in (0,1,2)'::jsquery; + jsquery +------------------ + "a" IN (0, 1, 2) +(1 row) + +select 'a IN (0,null, "null", xxx, "zzz", 2)'::jsquery; + jsquery +------------------------------------------- + "a" IN (0, null, "null", "xxx", "zzz", 2) +(1 row) + +select 'not < 1'::jsquery; + jsquery +----------- + "not" < 1 +(1 row) + +select 'not not < 1'::jsquery; + jsquery +----------------- + (NOT "not" < 1) +(1 row) + +select 'not( not < 1)'::jsquery; + jsquery +----------------- + (NOT "not" < 1) +(1 row) + +select 'not.x < 1'::jsquery; + jsquery +--------------- + "not"."x" < 1 +(1 row) + +select 'x.not < 1'::jsquery; + 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 +---------- + "is" < 1 +(1 row) + +select 'in < 1'::jsquery; + jsquery +---------- + "in" < 1 +(1 row) + +select 'not is < 1'::jsquery; + jsquery +---------------- + (NOT "is" < 1) +(1 row) + +select 'not in < 1'::jsquery; + jsquery +---------------- + (NOT "in" < 1) +(1 row) + +select 'in in (1,2)'::jsquery; + jsquery +---------------- + "in" IN (1, 2) +(1 row) + +select 'is in (1,2)'::jsquery; + jsquery +---------------- + "is" IN (1, 2) +(1 row) + +select 'not in (1,2)'::jsquery; + jsquery +----------------- + "not" IN (1, 2) +(1 row) + +select 'in is numeric'::jsquery; + jsquery +----------------- + "in" IS NUMERIC +(1 row) + +select 'is is numeric'::jsquery; + jsquery +----------------- + "is" IS NUMERIC +(1 row) + +select 'not is numeric'::jsquery; + jsquery +------------------ + "not" IS NUMERIC +(1 row) + +select 'not.in < 1'::jsquery; + jsquery +---------------- + "not"."in" < 1 +(1 row) + +select 'not.is < 1'::jsquery; + jsquery +---------------- + "not"."is" < 1 +(1 row) + +select 'not.not < 1'::jsquery; + jsquery +----------------- + "not"."not" < 1 +(1 row) + +select 'in.in < 1'::jsquery; + jsquery +--------------- + "in"."in" < 1 +(1 row) + +select 'in.is < 1'::jsquery; + jsquery +--------------- + "in"."is" < 1 +(1 row) + +select 'in.not < 1'::jsquery; + jsquery +---------------- + "in"."not" < 1 +(1 row) + +select 'is.in < 1'::jsquery; + jsquery +--------------- + "is"."in" < 1 +(1 row) + +select 'is.is < 1'::jsquery; + jsquery +--------------- + "is"."is" < 1 +(1 row) + +select 'is.not < 1'::jsquery; + jsquery +---------------- + "is"."not" < 1 +(1 row) + +select 'a.b.#4 > 4'::jsquery; + jsquery +---------------- + "a"."b".#4 > 4 +(1 row) + +select 'a.b.#10203.* > 4'::jsquery; + jsquery +---------------------- + "a"."b".#10203.* > 4 +(1 row) + +select '{"a": {"b": null}}'::jsonb @@ 'a.b = 1'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": null}}'::jsonb @@ 'a.b = null'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": null}}'::jsonb @@ 'a.b = false'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": false}}'::jsonb @@ 'a.b = false'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": false}}'::jsonb @@ 'a.b = true'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": true}}'::jsonb @@ 'a.b = true'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 1'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 1'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 1'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 1'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 1'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 2'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 2'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 2'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 2'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 2'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b = 0'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b < 0'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b <= 0'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b >= 0'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.b > 0'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ '*.b > 0'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ '*.b > 0'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.* > 0'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1}}'::jsonb @@ 'a.* > 0'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 1 ]'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b @> [ 1 ]'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b <@ [ 1 ]'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b @> [ 1,2,3,4 ]'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b <@ [ 1,2,3,4 ]'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a": 2}, {"a": 3}]'::jsonb @@ '*.a = 4'::jsquery; + ?column? +---------- + f +(1 row) + +select '[{"a": 2}, {"a": 3}]'::jsonb @@ '*.a = 3'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.a = 4'::jsquery; + ?column? +---------- + f +(1 row) + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.a = 4'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 1 OR a=3)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 OR a=1)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 and a=1)'::jsquery; + ?column? +---------- + f +(1 row) + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#(a = 3 and a=2)'::jsquery as "false"; + false +------- + f +(1 row) + +select '[{"a": 2, "b":3}, {"a": 3, "b": 1}]'::jsonb @@ '#(b = 1 and a=3)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.a.a = 4'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.a.a = 4'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '*.#.a.a = 4'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a": 2}, {"a": 3}, {"a": {"a":4}}]'::jsonb @@ '#.*.a.a = 4'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": 1}'::jsonb @@ 'a in (0,1,2)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": 1}'::jsonb @@ 'a in (0,2)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#=2'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 5 ]'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a=*'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b=*'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.c=*'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b = [1,2,3]'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# = [1,2,3]'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b && [1,2,3]'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# && [1,2,3]'::jsquery; + ?column? +---------- + f +(1 row) + +select 'asd.# = 3'::jsquery & 'zzz = true' | 'xxx.# = zero'::jsquery; + ?column? +------------------------------------------------------ + (("asd".# = 3 AND "zzz" = true) OR "xxx".# = "zero") +(1 row) + +select !'asd.# = 3'::jsquery & 'zzz = true' | !'xxx.# = zero'::jsquery; + ?column? +------------------------------------------------------------------ + (((NOT "asd".# = 3) AND "zzz" = true) OR (NOT "xxx".# = "zero")) +(1 row) + +select !'asd.#3.f = 3'::jsquery & 'zzz = true' | !'xxx.# = zero'::jsquery; + ?column? +----------------------------------------------------------------------- + (((NOT "asd".#3."f" = 3) AND "zzz" = true) OR (NOT "xxx".# = "zero")) +(1 row) + +select '{"x":[0,1,1,2]}'::jsonb @@ 'x @> [1,0]'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"x":[0,1,1,2]}'::jsonb @@ 'x @> [1,0,1]'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"x":[0,1,1,2]}'::jsonb @@ 'x @> [1,0,3]'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b && [ 2 ]'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.b($ && [ 2 ])'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.$.b && [ 2 ]'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.$.b ($ && [ 2 ])'::jsquery; + ?column? +---------- + t +(1 row) + +select '[1,2,3]'::jsonb @@ '# && [2]'::jsquery; + ?column? +---------- + f +(1 row) + +select '[1,2,3]'::jsonb @@ '#($ && [2])'::jsquery; + ?column? +---------- + f +(1 row) + +select '[1,2,3]'::jsonb @@ '$ && [2]'::jsquery; + ?column? +---------- + t +(1 row) + +select '[1,2,3]'::jsonb @@ '$ ($ && [2])'::jsquery; + ?column? +---------- + t +(1 row) + +select '[1,2,3]'::jsonb @@ '$ = 2'::jsquery; + ?column? +---------- + f +(1 row) + +select '[1,2,3]'::jsonb @@ '# = 2'::jsquery; + ?column? +---------- + t +(1 row) + +select '[1,2,3]'::jsonb @@ '#.$ = 2'::jsquery; + ?column? +---------- + t +(1 row) + +select '[1,2,3]'::jsonb @@ '#($ = 2)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[3,4]'::jsonb @@ '#($ > 2 and $ < 5)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[3,4]'::jsonb @@ '# > 2 and # < 5'::jsquery; + ?column? +---------- + t +(1 row) + +select '[1,6]'::jsonb @@ '#($ > 2 and $ < 5)'::jsquery; + ?column? +---------- + f +(1 row) + +select '[1,6]'::jsonb @@ '# > 2 and # < 5'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%.b=3'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ 'a.%=3'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%.%="hey"'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%="hey"'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 3, "c": "hey"}, "x": [5,6]}'::jsonb @@ '%=[5,6]'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#1 = 2'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#2 = 2'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.#3 = 2'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#1.x = 2'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#2.x = 2'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": [{"x":1},{"x":2},{"x":3}]}}'::jsonb @@ 'a.b.#3.x = 2'::jsquery; + ?column? +---------- + f +(1 row) + +select '"XXX"'::jsonb @@ '$="XXX"'::jsquery; + ?column? +---------- + t +(1 row) + +select '"XXX"'::jsonb @@ '#.$="XXX"'::jsquery; + ?column? +---------- + f +(1 row) + +--Unicode +select 'a\t = "dollar \u0024 character"'::jsquery; + jsquery +------------------------------ + "a\t" = "dollar $ character" +(1 row) + +select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar \u0024 character"'::jsquery; + ?column? +---------- + t +(1 row) + +select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar $ character"'::jsquery; + ?column? +---------- + t +(1 row) + +select '{ "a": "dollar $ character" }'::jsonb @@ '* = "dollar \u0024 character"'::jsquery; + ?column? +---------- + t +(1 row) + +select 'a\r = "\n\""'::jsquery; + jsquery +---------------- + "a\r" = "\n\"" +(1 row) + +select 'a\r = "\u0000"'::jsquery; +ERROR: unsupported Unicode escape sequence +LINE 1: select 'a\r = "\u0000"'::jsquery; + ^ +DETAIL: \u0000 cannot be converted to text. +select 'a\r = \u0000'::jsquery; +ERROR: unsupported Unicode escape sequence +LINE 1: select 'a\r = \u0000'::jsquery; + ^ +DETAIL: \u0000 cannot be converted to text. +select 'a\r = "\abcd"'::jsquery AS err; +ERROR: bad jsquery representation +LINE 1: select 'a\r = "\abcd"'::jsquery AS err; + ^ +DETAIL: Escape sequence is invalid at or near "\a" +select 'a\r = "\\abcd"'::jsquery; + jsquery +------------------ + "a\r" = "\\abcd" +(1 row) + +select 'a\r = "x\u0000"'::jsquery; +ERROR: unsupported Unicode escape sequence +LINE 1: select 'a\r = "x\u0000"'::jsquery; + ^ +DETAIL: \u0000 cannot be converted to text. +select 'a\r = x\u0000'::jsquery; +ERROR: unsupported Unicode escape sequence +LINE 1: select 'a\r = x\u0000'::jsquery; + ^ +DETAIL: \u0000 cannot be converted to text. +select 'a\r = "x\abcd"'::jsquery AS err; +ERROR: bad jsquery representation +LINE 1: select 'a\r = "x\abcd"'::jsquery AS err; + ^ +DETAIL: Escape sequence is invalid at or near "\a" +select 'a\r = "x\\abcd"'::jsquery; + jsquery +------------------- + "a\r" = "x\\abcd" +(1 row) + +select 'a\r = "x\u0000x"'::jsquery; +ERROR: unsupported Unicode escape sequence +LINE 1: select 'a\r = "x\u0000x"'::jsquery; + ^ +DETAIL: \u0000 cannot be converted to text. +select 'a\r = x\u0000x'::jsquery; +ERROR: unsupported Unicode escape sequence +LINE 1: select 'a\r = x\u0000x'::jsquery; + ^ +DETAIL: \u0000 cannot be converted to text. +select 'a\r = "x\abcdx"'::jsquery AS err; +ERROR: bad jsquery representation +LINE 1: select 'a\r = "x\abcdx"'::jsquery AS err; + ^ +DETAIL: Escape sequence is invalid at or near "\a" +select 'a\r = "x\\abcdx"'::jsquery; + jsquery +-------------------- + "a\r" = "x\\abcdx" +(1 row) + +select 'a\r = "\u0000x"'::jsquery; +ERROR: unsupported Unicode escape sequence +LINE 1: select 'a\r = "\u0000x"'::jsquery; + ^ +DETAIL: \u0000 cannot be converted to text. +select 'a\r = \u0000x'::jsquery; +ERROR: unsupported Unicode escape sequence +LINE 1: select 'a\r = \u0000x'::jsquery; + ^ +DETAIL: \u0000 cannot be converted to text. +select 'a\r = "\abcdx"'::jsquery AS err; +ERROR: bad jsquery representation +LINE 1: select 'a\r = "\abcdx"'::jsquery AS err; + ^ +DETAIL: Escape sequence is invalid at or near "\a" +select 'a\r = "\\abcdx"'::jsquery; + jsquery +------------------- + "a\r" = "\\abcdx" +(1 row) + +select 'a\r = x"\\abcd"'::jsquery AS err; +ERROR: bad jsquery representation +LINE 1: select 'a\r = x"\\abcd"'::jsquery AS err; + ^ +DETAIL: syntax error, unexpected STRING_P, expecting end of file at or near """ +--IS +select 'as IS boolean OR as is ARRAY OR as is ObJect OR as is Numeric OR as is string'::jsquery; + jsquery +------------------------------------------------------------------------------------------------- + (((("as" IS BOOLEAN OR "as" IS ARRAY) OR "as" IS OBJECT) OR "as" IS NUMERIC) OR "as" IS STRING) +(1 row) + +select '{"as": "xxx"}' @@ 'as IS string'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"as": "xxx"}' @@ 'as IS boolean OR as is ARRAY OR as is ObJect OR as is Numeric'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"as": 5}' @@ 'as is Numeric'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"as": true}' @@ 'as is boolean'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"as": false}' @@ 'as is boolean'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"as": "false"}' @@ 'as is boolean'::jsquery; + ?column? +---------- + f +(1 row) + +select '["xxx"]' @@ '$ IS array'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"as": false}' @@ '$ IS object'::jsquery; + ?column? +---------- + t +(1 row) + +select '"xxx"' @@ '$ IS string'::jsquery; + ?column? +---------- + t +(1 row) + +select '"xxx"' @@ '$ IS numeric'::jsquery; + ?column? +---------- + f +(1 row) + +--hint +select 'a /*-- noindex */ = 5'::jsquery; + jsquery +-------------------------- + "a" /*-- noindex */ = 5 +(1 row) + +select 'a /*-- index */ = 5'::jsquery; + jsquery +------------------------ + "a" /*-- index */ = 5 +(1 row) + +select 'asd.# = 3'::jsquery & 'zzz /*-- noindex */ = true' | 'xxx.# /*-- index */ = zero'; + ?column? +-------------------------------------------------------------------------------------- + (("asd".# = 3 AND "zzz" /*-- noindex */ = true) OR "xxx".# /*-- index */ = "zero") +(1 row) + +select 'a /*-- xxx */ = 5'::jsquery; + jsquery +--------- + "a" = 5 +(1 row) + +select 'a /* index */ = 5'::jsquery; + jsquery +--------- + "a" = 5 +(1 row) + +select 'a /* noindex */ = 5'::jsquery; + jsquery +--------- + "a" = 5 +(1 row) + +select 'a = /*-- noindex */ 5'::jsquery; +ERROR: bad jsquery representation +LINE 1: select 'a = /*-- noindex */ 5'::jsquery; + ^ +DETAIL: syntax error, unexpected HINT_P at or near "*/" +select 'a = /* noindex */ 5'::jsquery; + jsquery +--------- + "a" = 5 +(1 row) + +--LENGTH +select 'a.@# = 4'::jsquery; + jsquery +------------ + "a".@# = 4 +(1 row) + +select 'a.@#.$ = 4'::jsquery as noerror; + noerror +-------------- + "a".@#.$ = 4 +(1 row) + +select 'a.@#.a = 4'::jsquery as error; +ERROR: Array length should be last in path +LINE 1: select 'a.@#.a = 4'::jsquery as error; + ^ +select 'a.@#.* = 4'::jsquery as error; +ERROR: Array length should be last in path +LINE 1: select 'a.@#.* = 4'::jsquery as error; + ^ +select 'a.@#.% = 4'::jsquery as error; +ERROR: Array length should be last in path +LINE 1: select 'a.@#.% = 4'::jsquery as error; + ^ +select 'a.@#.# = 4'::jsquery as error; +ERROR: Array length should be last in path +LINE 1: select 'a.@#.# = 4'::jsquery as error; + ^ +select 'a.@#.*: = 4'::jsquery as error; +ERROR: Array length should be last in path +LINE 1: select 'a.@#.*: = 4'::jsquery as error; + ^ +select 'a.@#.%: = 4'::jsquery as error; +ERROR: Array length should be last in path +LINE 1: select 'a.@#.%: = 4'::jsquery as error; + ^ +select 'a.@#.#: = 4'::jsquery as error; +ERROR: Array length should be last in path +LINE 1: select 'a.@#.#: = 4'::jsquery as error; + ^ +select 'a.@# (a = 5 or b = 6)'::jsquery as error; +ERROR: Array length should be last in path +LINE 1: select 'a.@# (a = 5 or b = 6)'::jsquery as error; + ^ +select '[]' @@ '@# = 0'::jsquery; + ?column? +---------- + t +(1 row) + +select '[]' @@ '@# < 2'::jsquery; + ?column? +---------- + t +(1 row) + +select '[]' @@ '@# > 1'::jsquery; + ?column? +---------- + f +(1 row) + +select '[1]' @@ '@# = 0'::jsquery; + ?column? +---------- + f +(1 row) + +select '[1]' @@ '@# < 2'::jsquery; + ?column? +---------- + t +(1 row) + +select '[1]' @@ '@# > 1'::jsquery; + ?column? +---------- + f +(1 row) + +select '[1,2]' @@ '@# = 0'::jsquery; + ?column? +---------- + f +(1 row) + +select '[1,2]' @@ '@# < 2'::jsquery; + ?column? +---------- + f +(1 row) + +select '[1,2]' @@ '@# > 1'::jsquery; + ?column? +---------- + t +(1 row) + +select '[1,2]' @@ '@# in (1, 2)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[1,2]' @@ '@# in (1, 3)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":[1,2]}' @@ '@# in (2, 4)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":[1,2]}' @@ 'a.@# in (2, 4)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":[1,2]}' @@ '%.@# in (2, 4)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":[1,2]}' @@ '*.@# in (2, 4)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":[1,2]}' @@ '*.@# ($ = 4 or $ = 2)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":[1,2]}' @@ '@# = 1'::jsquery; + ?column? +---------- + t +(1 row) + +--filter +select '?( not b>0). x'::jsquery; + jsquery +------------------------ + ?((NOT "b" > 0)) ."x" +(1 row) + +select 'a.?(b>0 and x= 0 ) .c'::jsquery; + jsquery +------------------------------------ + "a". ?(("b" > 0 AND "x" = 0)) ."c" +(1 row) + +select 'a.$. ?(b>0 and x= 0 ) . c.k'::jsquery; + jsquery +------------------------------------------ + "a".$. ?(("b" > 0 AND "x" = 0)) ."c"."k" +(1 row) + +select 'a.$.? (b>0 and x.*= 0 ).c.k'::jsquery; + jsquery +-------------------------------------------- + "a".$. ?(("b" > 0 AND "x".* = 0)) ."c"."k" +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a < 0) (b=20)'::jsquery; + ?column? +---------- + f +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 0) (b=20)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 1) (b=20)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 2) (b=20)'::jsquery; + ?column? +---------- + f +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb @@ '#. ?(a > 3) (b=20)'::jsquery; + ?column? +---------- + f +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#.a'::jsquery; + ?column? +---------- + [1, 2] +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}]'::jsonb ~~ '#. ?(a > 1). b'::jsquery; + ?column? +---------- + [20] +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '# . ?(a > 1)'::jsquery; + ?column? +---------------------------------------- + [{"a": 2, "b": 20}, {"a": 3, "b": 30}] +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '%'::jsquery; + ?column? +---------- + +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '%'::jsquery; + ?column? +----------- + [1, 2, 3] +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 )'::jsquery; + ?column? +---------- + [3] +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '% . ? ( $ > 2 ).$'::jsquery; + ?column? +---------- + [3] +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( % > 2 )'::jsquery; + ?column? +---------------------------- + [{"a": 1, "b": 2, "c": 3}] +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 0 )'::jsquery; + ?column? +---------------------------- + [{"a": 1, "b": 2, "c": 3}] +(1 row) + +select '{"a":1, "b":2, "c":3}'::jsonb ~~ '? ( %: > 2 )'::jsquery; + ?column? +---------- + +(1 row) + +select '[{"a":1, "b":10}, {"a":2, "b":20}, {"a":3, "b":30}]'::jsonb ~~ '#'::jsquery; + ?column? +----------------------------------------------------------- + [{"a": 1, "b": 10}, {"a": 2, "b": 20}, {"a": 3, "b": 30}] +(1 row) + +select '[1,2,3]'::jsonb ~~ '#'::jsquery; + ?column? +----------- + [1, 2, 3] +(1 row) + +select '[1,2,3]'::jsonb ~~ '#. ?($ > 2)'::jsquery; + ?column? +---------- + [3] +(1 row) + +select '[1,2,3]'::jsonb ~~ '#. ?($ > 2).$'::jsquery; + ?column? +---------- + [3] +(1 row) + +select '[1,2,3]'::jsonb ~~ ' ?(#.$ > 2).$'::jsquery; + ?column? +------------- + [[1, 2, 3]] +(1 row) + +select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 2).$'::jsquery; + ?column? +---------- + +(1 row) + +select '[1,2,3]'::jsonb ~~ ' ?(#:.$ > 0).$'::jsquery; + ?column? +------------- + [[1, 2, 3]] +(1 row) + +select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '*.?(c >0)'::jsquery; + ?column? +------------ + [{"c": 1}] +(1 row) + +select '{"a": {"b": {"c": 1}}}'::jsonb ~~ '?(*.c >0)'::jsquery; + ?column? +-------------------------- + [{"a": {"b": {"c": 1}}}] +(1 row) + +select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term.#. ? ( $ = "NYC")'::jsquery; + ?column? +---------- + ["NYC"] +(1 row) + +select '{"tags":[{"term":["NYC", "CYN"]}, {"term":["1NYC", "1CYN"]} ]}'::jsonb ~~ 'tags.#.term. ? ( # = "NYC")'::jsquery; + ?column? +------------------ + [["NYC", "CYN"]] +(1 row) + +--ALL +select 'a.*: = 4'::jsquery; + jsquery +------------ + "a".*: = 4 +(1 row) + +select '%: = 4'::jsquery; + jsquery +--------- + %: = 4 +(1 row) + +select '#:.i = 4'::jsquery; + jsquery +------------ + #:."i" = 4 +(1 row) + +select '[]' @@ '#: ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[2,3,4]' @@ '#: ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[2,3,5]' @@ '#: ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + f +(1 row) + +select '[2,3,5]' @@ '# ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + t +(1 row) + +select '[2,3,"x"]' @@ '#: ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{}' @@ '%: ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{}' @@ '*: ($ is object)'::jsquery; + ?column? +---------- + t +(1 row) + +select '"a"' @@ '*: is string'::jsquery; + ?column? +---------- + t +(1 row) + +select '1' @@ '*: is string'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":2,"b":3,"c":4}' @@ '%: ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":2,"b":3,"c":5}' @@ '%: ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":2,"b":3,"c":5}' @@ '% ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":2,"b":3,"c":"x"}' @@ '%: ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":2,"b":3,"c":4}' @@ '*: ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":2,"b":3,"c":5}' @@ '*: ($ > 1 and $ < 5)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":2,"b":3,"c":4}' @@ '*: ($ is object OR ($> 1 and $ < 5))'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":2,"b":3,"c":5}' @@ '*: ($ is object OR ($> 1 and $ < 5))'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"b":{"ba":3, "bb":4}}' @@ '*: ($ is object OR ($ > 1 and $ < 5))'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"b":{"ba":3, "bb":5}}' @@ '*: ($ is object OR ($> 1 and $ < 5))'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":{"aa":1, "ab":2}, "b":{"ba":3, "bb":4}}' @@ '*: ($ is object OR ($ > 0 and $ < 5))'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":{"aa":1, "ab":2}, "b":{"ba":3, "bb":5}}' @@ '*: ($ is object OR ($> 0 and $ < 5))'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":{"aa":1, "ab":2}, "b":{"ba":3, "bb":5}}' @@ '* ($ > 0 and $ < 5)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":{"aa":1, "ab":2}, "b":{"ba":3, "bb":5}}' @@ '*: ($ is object OR $ is numeric)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":{"aa":1, "ab":2}, "b":[5,6]}' @@ '*: ($ is object OR $ is numeric)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":{"aa":1, "ab":2}, "b":[5,6]}' @@ '*: ($ is object OR $ is array OR $ is numeric)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":{"aa":1, "ab":2}, "b":[5,6, {"c":8}]}' @@ '*: ($ is object OR $ is array OR $ is numeric)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":{"aa":1, "ab":2}, "b":[5,6, {"c":"x"}]}' @@ '*: ($ is object OR $ is array OR $ is numeric)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":{"aa":1, "ab":2}, "b":[5,6, {"c":null}]}' @@ '*: ($ is object OR $ is array OR $ is numeric)'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '%:.aa is numeric'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":{"aa":1}, "b":{"aa":true, "bb":2}}' @@ '%:.aa is numeric'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}, "aa":16}' @@ '*: (not $ is object or $.aa is numeric)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '*: (not $ is object or $.aa is numeric or % is object)'::jsquery; + ?column? +---------- + t +(1 row) + +SELECT 'test.# IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64)'::jsquery; + jsquery +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + "test".# IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64) +(1 row) + +select '[]' @@ '(@# > 0 and #: = 16)'::jsquery; + ?column? +---------- + f +(1 row) + +select '[16]' @@ '(@# > 0 and #: = 16)'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b or b.d'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c or b.d'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.d'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g or b.c'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.b and b.d'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.d'::jsquery; + ?column? +---------- + t +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.c and b.b'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb @@ 'a.g and b.d'::jsquery; + ?column? +---------- + f +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.d'::jsquery; + ?column? +---------- + [1, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and b.c'::jsquery; + ?column? +---------- + +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.d or b.c)'::jsquery; + ?column? +---------- + [1, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and (b.c or b.d)'::jsquery; + ?column? +---------- + [1, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b and a.c and b.d'::jsquery; + ?column? +----------- + [1, 2, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.b or a.c) and b.d'::jsquery; + ?column? +---------- + [1, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.c) and b.d'::jsquery; + ?column? +---------- + [2, 3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ '(a.e or a.g) and b.d'::jsquery; + ?column? +---------- + +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'a.b or (b.d or b.c)'::jsquery; + ?column? +---------- + [1] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b or a.c)'::jsquery; + ?column? +---------- + [3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d or (a.b and a.c)'::jsquery; + ?column? +---------- + [3] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.f or (a.b and a.c)'::jsquery; + ?column? +---------- + [1, 2] +(1 row) + +select '{"a": {"b": 1, "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'::jsquery; + ?column? +----------- + [3, 1, 2] +(1 row) + +select '{"a": {"b": [6,5,4], "c": 2}, "b": {"d":3}}'::jsonb ~~ 'b.d and (a.b and a.c)'::jsquery; + ?column? +------------------- + [3, [6, 5, 4], 2] +(1 row) + +--extract entries for index scan +SELECT gin_debug_query_path_value('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5'); + gin_debug_query_path_value +---------------------------- + AND + + z = 5 , entry 0 + + OR + + x.y.a = 1 , entry 1 + + x.y.b = 2 , entry 2 + + +(1 row) + +SELECT gin_debug_query_path_value('NOT #(x=1) and NOT *(y=1) and NOT %(z=1) '); + gin_debug_query_path_value +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_path_value('#(NOT x=1) and *(NOT y=1) and %(NOT z=1) '); + gin_debug_query_path_value +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_path_value('NOT #(NOT x=1) and NOT *(NOT y=1) and NOT %(NOT z=1) '); + gin_debug_query_path_value +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_path_value('#(x = "a" and y > 0 and y < 1 and z > 0)'); + gin_debug_query_path_value +---------------------------- + #.x = "a" , entry 0 + + +(1 row) + +SELECT gin_debug_query_path_value('#(x = "a" and y /*-- index */ >= 0 and y < 1 and z > 0)'); + gin_debug_query_path_value +----------------------------- + AND + + #.x = "a" , entry 0 + + #.y >= 0 , < 1 , entry 1 + + +(1 row) + +SELECT gin_debug_query_path_value('#(x /*-- noindex */ = "a" and y > 0 and y <= 1 and z /*-- index */ > 0)'); + gin_debug_query_path_value +----------------------------- + AND + + #.y > 0 , <= 1 , entry 0 + + #.z > 0 , entry 1 + + +(1 row) + +SELECT gin_debug_query_path_value('x = 1 and (y /*-- index */ > 0 and y < 1 OR z > 0)'); + gin_debug_query_path_value +---------------------------- + AND + + x = 1 , entry 0 + + OR + + y > 0 , < 1 , entry 1 + + z > 0 , entry 2 + + +(1 row) + +SELECT gin_debug_query_path_value('%.x = 1'); + gin_debug_query_path_value +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_path_value('*.x = "b"'); + gin_debug_query_path_value +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_path_value('x && [1,2,3]'); + gin_debug_query_path_value +---------------------------- + OR + + x.# = 1 , entry 0 + + x.# = 2 , entry 1 + + x.# = 3 , entry 2 + + +(1 row) + +SELECT gin_debug_query_path_value('x @> [1,2,3]'); + gin_debug_query_path_value +---------------------------- + AND + + x.# = 1 , entry 0 + + x.# = 2 , entry 1 + + x.# = 3 , entry 2 + + +(1 row) + +SELECT gin_debug_query_path_value('x <@ [1,2,3]'); + gin_debug_query_path_value +---------------------------- + OR + + x = [] , entry 0 + + x.# = 1 , entry 1 + + x.# = 2 , entry 2 + + x.# = 3 , entry 3 + + +(1 row) + +SELECT gin_debug_query_path_value('x = *'); + gin_debug_query_path_value +---------------------------- + x = * , entry 0 + + +(1 row) + +SELECT gin_debug_query_path_value('x is boolean'); + gin_debug_query_path_value +---------------------------- + x IS boolean , entry 0 + + +(1 row) + +SELECT gin_debug_query_path_value('x is string'); + gin_debug_query_path_value +---------------------------- + x IS string , entry 0 + + +(1 row) + +SELECT gin_debug_query_path_value('x is numeric'); + gin_debug_query_path_value +---------------------------- + x IS numeric , entry 0 + + +(1 row) + +SELECT gin_debug_query_path_value('x is array'); + gin_debug_query_path_value +---------------------------- + x IS array , entry 0 + + +(1 row) + +SELECT gin_debug_query_path_value('x is object'); + gin_debug_query_path_value +---------------------------- + x IS object , entry 0 + + +(1 row) + +SELECT gin_debug_query_path_value('#:(x=1) AND %:(y=1) AND *:(z=1)'); + gin_debug_query_path_value +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_path_value('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)'); + gin_debug_query_path_value +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_path_value('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)'); + gin_debug_query_path_value +---------------------------- + #.x = 1 , entry 0 + + +(1 row) + +SELECT gin_debug_query_path_value('$ = true'); + gin_debug_query_path_value +---------------------------- + $ = true , entry 0 + + +(1 row) + +SELECT gin_debug_query_path_value('$ . ? (review_votes > 10) . review_rating < 7'); + gin_debug_query_path_value +-------------------------------- + AND + + review_rating < 7 , entry 0 + + review_votes > 10 , entry 1 + + +(1 row) + +SELECT gin_debug_query_path_value('similar_product_ids . ? (# = "B0002W4TL2") . $'); + gin_debug_query_path_value +------------------------------------------------- + similar_product_ids.# = "B0002W4TL2" , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5'); + gin_debug_query_value_path +---------------------------- + AND + + z = 5 , entry 0 + + OR + + x.y.a = 1 , entry 1 + + x.y.b = 2 , entry 2 + + +(1 row) + +SELECT gin_debug_query_value_path('NOT #(x=1) and NOT *(y=1) and NOT %(z=1) '); + gin_debug_query_value_path +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_value_path('#(NOT x=1) and *(NOT y=1) and %(NOT z=1) '); + gin_debug_query_value_path +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_value_path('NOT #(NOT x=1) and NOT *(NOT y=1) and NOT %(NOT z=1) '); + gin_debug_query_value_path +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_value_path('#(x = "a" and y > 0 and y < 1 and z > 0)'); + gin_debug_query_value_path +---------------------------- + #.x = "a" , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('#(x = "a" and y /*-- index */ >= 0 and y < 1 and z > 0)'); + gin_debug_query_value_path +----------------------------- + AND + + #.x = "a" , entry 0 + + #.y >= 0 , < 1 , entry 1 + + +(1 row) + +SELECT gin_debug_query_value_path('#(x /*-- noindex */ = "a" and y > 0 and y <= 1 and z /*-- index */ > 0)'); + gin_debug_query_value_path +----------------------------- + AND + + #.y > 0 , <= 1 , entry 0 + + #.z > 0 , entry 1 + + +(1 row) + +SELECT gin_debug_query_value_path('x = 1 and (y /*-- index */ > 0 and y < 1 OR z > 0)'); + gin_debug_query_value_path +---------------------------- + AND + + x = 1 , entry 0 + + OR + + y > 0 , < 1 , entry 1 + + z > 0 , entry 2 + + +(1 row) + +SELECT gin_debug_query_value_path('%.x = 1'); + gin_debug_query_value_path +---------------------------- + %.x = 1 , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('*.x = "b"'); + gin_debug_query_value_path +---------------------------- + *.x = "b" , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('x && [1,2,3]'); + gin_debug_query_value_path +---------------------------- + OR + + x.# = 1 , entry 0 + + x.# = 2 , entry 1 + + x.# = 3 , entry 2 + + +(1 row) + +SELECT gin_debug_query_value_path('x @> [1,2,3]'); + gin_debug_query_value_path +---------------------------- + AND + + x.# = 1 , entry 0 + + x.# = 2 , entry 1 + + x.# = 3 , entry 2 + + +(1 row) + +SELECT gin_debug_query_value_path('x <@ [1,2,3]'); + gin_debug_query_value_path +---------------------------- + OR + + x = [] , entry 0 + + x.# = 1 , entry 1 + + x.# = 2 , entry 2 + + x.# = 3 , entry 3 + + +(1 row) + +SELECT gin_debug_query_value_path('x = [1,2,3]'); + gin_debug_query_value_path +---------------------------- + AND + + x.# = 1 , entry 0 + + x.# = 2 , entry 1 + + x.# = 3 , entry 2 + + +(1 row) + +SELECT gin_debug_query_value_path('x = *'); + gin_debug_query_value_path +---------------------------- + x = * , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('x is boolean'); + gin_debug_query_value_path +---------------------------- + x IS boolean , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('x is string'); + gin_debug_query_value_path +---------------------------- + x IS string , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('x is numeric'); + gin_debug_query_value_path +---------------------------- + x IS numeric , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('x is array'); + gin_debug_query_value_path +---------------------------- + x IS array , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('x is object'); + gin_debug_query_value_path +---------------------------- + x IS object , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('#:(x=1) AND %:(y=1) AND *:(z=1)'); + gin_debug_query_value_path +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_value_path('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)'); + gin_debug_query_value_path +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_value_path('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)'); + gin_debug_query_value_path +---------------------------- + AND + + #.x = 1 , entry 0 + + %.y = 1 , entry 1 + + *.z = 1 , entry 2 + + +(1 row) + +SELECT gin_debug_query_value_path('(@# > 0 and #: = 16)'); + gin_debug_query_value_path +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_value_path('*.@# ($ = 4 or $ = 2)'); + gin_debug_query_value_path +---------------------------- + NULL + + +(1 row) + +SELECT gin_debug_query_value_path('tags.#.term. ? ( # = "NYC").x > 0'); + gin_debug_query_value_path +---------------------------------- + tags.#.term.# = "NYC" , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('$ = true'); + gin_debug_query_value_path +---------------------------- + $ = true , entry 0 + + +(1 row) + +SELECT gin_debug_query_value_path('$ . ? (review_votes > 10) . review_rating < 7'); + gin_debug_query_value_path +-------------------------------- + AND + + review_rating < 7 , entry 0 + + review_votes > 10 , entry 1 + + +(1 row) + +SELECT gin_debug_query_value_path('similar_product_ids . ? (# = "B0002W4TL2") . $'); + gin_debug_query_value_path +------------------------------------------------- + similar_product_ids.# = "B0002W4TL2" , entry 0 + + +(1 row) + +---table and index +select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 0; + count +------- + 654 +(1 row) + +select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 19; + count +------- + 13 +(1 row) + +select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 < 19; + count +------- + 985 +(1 row) + +select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 >= 19; + count +------- + 16 +(1 row) + +select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 <= 19; + count +------- + 988 +(1 row) + +select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 = 19; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 16 AND + (v->>'review_helpful_votes')::int4 < 20; + count +------- + 8 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; + count +------- + 654 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'::jsquery; + count +------- + 13 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'::jsquery; + count +------- + 985 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'::jsquery; + count +------- + 16 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'::jsquery; + count +------- + 988 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16'::jsquery AND + v @@ 'review_helpful_votes < 20'::jsquery; + count +------- + 8 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'::jsquery; + count +------- + 8 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'::jsquery; + count +------- + 8 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'::jsquery; + count +------- + 4 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'::jsquery; + count +------- + 54 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ 'customer_id = null'::jsquery; + count +------- + 1 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_votes = true'::jsquery; + count +------- + 1 +(1 row) + +select count(*) from test_jsquery where v @@ 'product_group = false'::jsquery; + count +------- + 1 +(1 row) + +select count(*) from test_jsquery where v @@ 't = *'::jsquery; + count +------- + 10 +(1 row) + +select count(*) from test_jsquery where v @@ 't is boolean'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is string'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is numeric'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is array'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is object'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is boolean'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is string'::jsquery; + count +------- + 4 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is numeric'::jsquery; + count +------- + 5 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is array'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is object'::jsquery; + count +------- + 1017 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'::jsquery; + count +------- + 51 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'::jsquery; + count +------- + 1001 +(1 row) + +select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery; + count +------- + 40 +(1 row) + +select count(*) from test_jsquery where v @@ '$ > 2'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ '$ = false'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't'::jsquery; + count +------- + 10 +(1 row) + +select count(*) from test_jsquery where v @@ '$'::jsquery; + count +------- + 1034 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'::jsquery; + count +------- + 1001 +(1 row) + +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'::jsquery; + count +------- + 79 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'::jsquery; + count +------- + 3 +(1 row) + +select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; + v +------------------- + {"array": [2]} + {"array": [2, 3]} +(2 rows) + +select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; + v +---------------------- + {"array": [2]} + {"array": [2, 3]} + {"array": [1, 2, 3]} + {"array": [2, 3, 4]} + {"array": [3, 4, 5]} +(5 rows) + +select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; + v +---------------------- + {"array": [2, 3]} + {"array": [1, 2, 3]} + {"array": [2, 3, 4]} +(3 rows) + +select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; + v +------------------- + {"array": [2, 3]} +(1 row) + +create index t_idx on test_jsquery using gin (v jsonb_value_path_ops); +set enable_seqscan = off; +explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; + QUERY PLAN +------------------------------------------------------------------------ + Aggregate + -> Bitmap Heap Scan on test_jsquery + Recheck Cond: (v @@ '"review_helpful_votes" > 0'::jsquery) + -> Bitmap Index Scan on t_idx + Index Cond: (v @@ '"review_helpful_votes" > 0'::jsquery) +(5 rows) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; + count +------- + 654 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'::jsquery; + count +------- + 13 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'::jsquery; + count +------- + 985 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'::jsquery; + count +------- + 16 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'::jsquery; + count +------- + 988 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16'::jsquery AND + v @@ 'review_helpful_votes < 20'::jsquery; + count +------- + 8 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'::jsquery; + count +------- + 8 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'::jsquery; + count +------- + 8 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'::jsquery; + count +------- + 4 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'::jsquery; + count +------- + 54 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ 'customer_id = null'::jsquery; + count +------- + 1 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_votes = true'::jsquery; + count +------- + 1 +(1 row) + +select count(*) from test_jsquery where v @@ 'product_group = false'::jsquery; + count +------- + 1 +(1 row) + +select count(*) from test_jsquery where v @@ 't = *'::jsquery; + count +------- + 10 +(1 row) + +select count(*) from test_jsquery where v @@ 't is boolean'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is string'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is numeric'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is array'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is object'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is boolean'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is string'::jsquery; + count +------- + 4 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is numeric'::jsquery; + count +------- + 5 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is array'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is object'::jsquery; + count +------- + 1017 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'::jsquery; + count +------- + 51 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'::jsquery; + count +------- + 1001 +(1 row) + +select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ '$ > 2'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ '$ = false'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't'::jsquery; + count +------- + 10 +(1 row) + +select count(*) from test_jsquery where v @@ '$'::jsquery; + count +------- + 1034 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'::jsquery; + count +------- + 1001 +(1 row) + +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'::jsquery; + count +------- + 79 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'::jsquery; + count +------- + 3 +(1 row) + +explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; + QUERY PLAN +--------------------------------------------------------------- + Sort + Sort Key: v + -> Bitmap Heap Scan on test_jsquery + Recheck Cond: (v @@ '"array" <@ [2, 3]'::jsquery) + -> Bitmap Index Scan on t_idx + Index Cond: (v @@ '"array" <@ [2, 3]'::jsquery) +(6 rows) + +explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; + QUERY PLAN +--------------------------------------------------------------- + Sort + Sort Key: v + -> Bitmap Heap Scan on test_jsquery + Recheck Cond: (v @@ '"array" && [2, 3]'::jsquery) + -> Bitmap Index Scan on t_idx + Index Cond: (v @@ '"array" && [2, 3]'::jsquery) +(6 rows) + +explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; + QUERY PLAN +--------------------------------------------------------------- + Sort + Sort Key: v + -> Bitmap Heap Scan on test_jsquery + Recheck Cond: (v @@ '"array" @> [2, 3]'::jsquery) + -> Bitmap Index Scan on t_idx + Index Cond: (v @@ '"array" @> [2, 3]'::jsquery) +(6 rows) + +explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; + QUERY PLAN +-------------------------------------------------------------- + Sort + Sort Key: v + -> Bitmap Heap Scan on test_jsquery + Recheck Cond: (v @@ '"array" = [2, 3]'::jsquery) + -> Bitmap Index Scan on t_idx + Index Cond: (v @@ '"array" = [2, 3]'::jsquery) +(6 rows) + +select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; + v +------------------- + {"array": [2]} + {"array": [2, 3]} +(2 rows) + +select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; + v +---------------------- + {"array": [2]} + {"array": [2, 3]} + {"array": [1, 2, 3]} + {"array": [2, 3, 4]} + {"array": [3, 4, 5]} +(5 rows) + +select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; + v +---------------------- + {"array": [2, 3]} + {"array": [1, 2, 3]} + {"array": [2, 3, 4]} +(3 rows) + +select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; + v +------------------- + {"array": [2, 3]} +(1 row) + +drop index t_idx; +create index t_idx on test_jsquery using gin (v jsonb_path_value_ops); +set enable_seqscan = off; +explain (costs off) select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; + QUERY PLAN +------------------------------------------------------------------------ + Aggregate + -> Bitmap Heap Scan on test_jsquery + Recheck Cond: (v @@ '"review_helpful_votes" > 0'::jsquery) + -> Bitmap Index Scan on t_idx + Index Cond: (v @@ '"review_helpful_votes" > 0'::jsquery) +(5 rows) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 0'::jsquery; + count +------- + 654 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 19'::jsquery; + count +------- + 13 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes < 19'::jsquery; + count +------- + 985 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes >= 19'::jsquery; + count +------- + 16 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes <= 19'::jsquery; + count +------- + 988 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes = 19'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16'::jsquery AND + v @@ 'review_helpful_votes < 20'::jsquery; + count +------- + 8 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes > 16 and review_helpful_votes < 20'::jsquery; + count +------- + 8 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_helpful_votes ($ > 16 and $ < 20)'::jsquery; + count +------- + 8 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"]'::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids(# = "0440180295") '::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#($ = "0440180295") '::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids && ["0440180295"] and product_sales_rank > 300000'::jsquery; + count +------- + 4 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids <@ ["B00000DG0U", "B00004SQXU", "B0001XAM18", "B00000FDBU", "B00000FDBV", "B000002H2H", "B000002H6C", "B000002H5E", "B000002H97", "B000002HMH"]'::jsquery; + count +------- + 54 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids @> ["B000002H2H", "B000002H6C"]'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ 'customer_id = null'::jsquery; + count +------- + 1 +(1 row) + +select count(*) from test_jsquery where v @@ 'review_votes = true'::jsquery; + count +------- + 1 +(1 row) + +select count(*) from test_jsquery where v @@ 'product_group = false'::jsquery; + count +------- + 1 +(1 row) + +select count(*) from test_jsquery where v @@ 't = *'::jsquery; + count +------- + 10 +(1 row) + +select count(*) from test_jsquery where v @@ 't is boolean'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is string'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is numeric'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is array'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't is object'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is boolean'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is string'::jsquery; + count +------- + 4 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is numeric'::jsquery; + count +------- + 5 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is array'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ '$ is object'::jsquery; + count +------- + 1017 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric'::jsquery; + count +------- + 51 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string'::jsquery; + count +------- + 1001 +(1 row) + +select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery; + count +------- + 7 +(1 row) + +select count(*) from test_jsquery where v @@ '$ > 2'::jsquery; + count +------- + 3 +(1 row) + +select count(*) from test_jsquery where v @@ '$ = false'::jsquery; + count +------- + 2 +(1 row) + +select count(*) from test_jsquery where v @@ 't'::jsquery; + count +------- + 10 +(1 row) + +select count(*) from test_jsquery where v @@ '$'::jsquery; + count +------- + 1034 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids.#'::jsquery; + count +------- + 950 +(1 row) + +select count(*) from test_jsquery where v @@ '$ . ? (review_votes > 10) . review_rating < 7'::jsquery; + count +------- + 79 +(1 row) + +select count(*) from test_jsquery where v @@ 'similar_product_ids . ? (# = "B0002W4TL2") . $'::jsquery; + count +------- + 3 +(1 row) + +explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; + QUERY PLAN +--------------------------------------------------------------- + Sort + Sort Key: v + -> Bitmap Heap Scan on test_jsquery + Recheck Cond: (v @@ '"array" <@ [2, 3]'::jsquery) + -> Bitmap Index Scan on t_idx + Index Cond: (v @@ '"array" <@ [2, 3]'::jsquery) +(6 rows) + +explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; + QUERY PLAN +--------------------------------------------------------------- + Sort + Sort Key: v + -> Bitmap Heap Scan on test_jsquery + Recheck Cond: (v @@ '"array" && [2, 3]'::jsquery) + -> Bitmap Index Scan on t_idx + Index Cond: (v @@ '"array" && [2, 3]'::jsquery) +(6 rows) + +explain (costs off) select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; + QUERY PLAN +--------------------------------------------------------------- + Sort + Sort Key: v + -> Bitmap Heap Scan on test_jsquery + Recheck Cond: (v @@ '"array" @> [2, 3]'::jsquery) + -> Bitmap Index Scan on t_idx + Index Cond: (v @@ '"array" @> [2, 3]'::jsquery) +(6 rows) + +explain (costs off) select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; + QUERY PLAN +-------------------------------------------------------------- + Sort + Sort Key: v + -> Bitmap Heap Scan on test_jsquery + Recheck Cond: (v @@ '"array" = [2, 3]'::jsquery) + -> Bitmap Index Scan on t_idx + Index Cond: (v @@ '"array" = [2, 3]'::jsquery) +(6 rows) + +select v from test_jsquery where v @@ 'array <@ [2,3]'::jsquery order by v; + v +------------------- + {"array": [2]} + {"array": [2, 3]} +(2 rows) + +select v from test_jsquery where v @@ 'array && [2,3]'::jsquery order by v; + v +---------------------- + {"array": [2]} + {"array": [2, 3]} + {"array": [1, 2, 3]} + {"array": [2, 3, 4]} + {"array": [3, 4, 5]} +(5 rows) + +select v from test_jsquery where v @@ 'array @> [2,3]'::jsquery order by v; + v +---------------------- + {"array": [2, 3]} + {"array": [1, 2, 3]} + {"array": [2, 3, 4]} +(3 rows) + +select v from test_jsquery where v @@ 'array = [2,3]'::jsquery order by v; + v +------------------- + {"array": [2, 3]} +(1 row) + +RESET enable_seqscan; From 15e66cdeb1ca2feec28c02f54759dbbd340f98f0 Mon Sep 17 00:00:00 2001 From: Daria Lepikhova Date: Mon, 12 Oct 2020 09:58:55 +0500 Subject: [PATCH 42/53] Added /*fall through*/ comments for fix warnings --- jsquery_extract.c | 1 + jsquery_io.c | 2 ++ jsquery_support.c | 10 +++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/jsquery_extract.c b/jsquery_extract.c index 1b61267..20da440 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -178,6 +178,7 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path) *result->exactValue = e; return result; } + /* fall through */ /* jqiEqual with jqiArray follows */ case jqiIn: case jqiOverlap: diff --git a/jsquery_io.c b/jsquery_io.c index 2e4c328..ff05cec 100644 --- a/jsquery_io.c +++ b/jsquery_io.c @@ -44,6 +44,7 @@ flattenJsQueryParseItem(StringInfo buf, JsQueryParseItem *item, bool onlyCurrent case jqiKey: if (onlyCurrentInPath) elog(ERROR,"Array length should be last in path"); + /* fall through */ case jqiString: appendBinaryStringInfo(buf, (char*)&item->string.len, sizeof(item->string.len)); appendBinaryStringInfo(buf, item->string.val, item->string.len); @@ -239,6 +240,7 @@ printJsQueryItem(StringInfo buf, JsQueryItem *v, bool inKey, bool printBracketes case jqiKey: if (inKey) appendStringInfoChar(buf, '.'); + /* fall through */ /* follow next */ case jqiString: escape_json(buf, jsqGetString(v, NULL)); diff --git a/jsquery_support.c b/jsquery_support.c index 278e561..196956a 100644 --- a/jsquery_support.c +++ b/jsquery_support.c @@ -33,10 +33,13 @@ alignStringInfoInt(StringInfo buf) { case 3: appendStringInfoCharMacro(buf, 0); + /* fall through */ case 2: appendStringInfoCharMacro(buf, 0); + /* fall through */ case 1: appendStringInfoCharMacro(buf, 0); + /* fall through */ default: break; } @@ -60,9 +63,9 @@ jsqInitByBuffer(JsQueryItem *v, char *base, int32 pos) switch(INTALIGN(pos) - pos) { - case 3: pos++; - case 2: pos++; - case 1: pos++; + case 3: pos++; /* fall through */ + case 2: pos++; /* fall through */ + case 1: pos++; /* fall through */ default: break; } @@ -86,6 +89,7 @@ jsqInitByBuffer(JsQueryItem *v, char *base, int32 pos) case jqiKey: case jqiString: read_int32(v->value.datalen, base, pos); + /* fall through */ /* follow next */ case jqiNumeric: case jqiBool: From 462e2b9e09afe66ac225fe7486f964b3c8de2ee5 Mon Sep 17 00:00:00 2001 From: Marina Polyakova Date: Tue, 10 Aug 2021 16:21:07 +0300 Subject: [PATCH 43/53] PGPRO-5414: Windows build fix for Postgres Pro Standard 15 In PostgreSQL 15 the variables contrib_extraincludes and contrib_extrasource from src/tools/msvc/Mkvcbuild.pm are no longer used. With this change the contrib module jsquery does not need them either. --- jsquery_gram.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsquery_gram.y b/jsquery_gram.y index 2d6d531..282f2dc 100644 --- a/jsquery_gram.y +++ b/jsquery_gram.y @@ -47,7 +47,7 @@ typedef struct string { int len; int total; } string; -#include +#include "jsquery_gram.h" /* flex 2.5.4 doesn't bother with a decl for this */ int jsquery_yylex(YYSTYPE * yylval_param); From ac2b4040a3058a1c402604e1cd203f6cd4fc6015 Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Tue, 9 Nov 2021 12:50:16 +0300 Subject: [PATCH 44/53] [PGPRO-5310] Mark variables used for assert only as such So, they would not cause warnings when build with --disable-cassert instide contrib tree --- jsquery_op.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jsquery_op.c b/jsquery_op.c index e848421..ee61f8e 100644 --- a/jsquery_op.c +++ b/jsquery_op.c @@ -542,7 +542,7 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg, else if (JsonbType(jb) == jbvScalar) { JsonbIterator *it; - int32 r; + int32 r PG_USED_FOR_ASSERTS_ONLY; JsonbValue v; it = JsonbIteratorInit(jb->val.binary.data); @@ -729,7 +729,7 @@ recursiveExecute(JsQueryItem *jsq, JsonbValue *jb, JsQueryItem *jsqLeftArg, if (JsonbType(jb) == jbvScalar) { JsonbIterator *it; - int32 r; + int32 r PG_USED_FOR_ASSERTS_ONLY; JsonbValue v; it = JsonbIteratorInit(jb->val.binary.data); From 84688d9e03274411e8ccf8c434a057f17e002057 Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Tue, 23 Nov 2021 15:10:10 +0300 Subject: [PATCH 45/53] Update copyright --- jsquery_io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/jsquery_io.c b/jsquery_io.c index ff05cec..ec44d5c 100644 --- a/jsquery_io.c +++ b/jsquery_io.c @@ -4,6 +4,7 @@ * I/O functions for jsquery datatype * * Copyright (c) 2014, PostgreSQL Global Development Group + * Portions Copyright (c) 2016-2021, Postgres Professional * Author: Teodor Sigaev * * IDENTIFICATION From 3293e48ae667f9c80904682c9234252a4cb39c25 Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Wed, 1 Dec 2021 11:35:51 +0300 Subject: [PATCH 46/53] Update copyright notices for files which are touched in Poshrespro Standard 14 release --- jsonb_gin_ops.c | 1 + jsquery.h | 1 + jsquery_constr.c | 1 + jsquery_extract.c | 1 + jsquery_gram.y | 1 + jsquery_op.c | 1 + jsquery_scan.l | 1 + jsquery_support.c | 1 + 8 files changed, 8 insertions(+) diff --git a/jsonb_gin_ops.c b/jsonb_gin_ops.c index a9bc22c..c63cad4 100644 --- a/jsonb_gin_ops.c +++ b/jsonb_gin_ops.c @@ -4,6 +4,7 @@ * Support GIN over jsonb with jsquery operation * * Copyright (c) 2014, PostgreSQL Global Development Group + * Portions Copyright (c) 2017-2021, Postgres Professional * Author: Alexander Korotkov * * IDENTIFICATION diff --git a/jsquery.h b/jsquery.h index 9563944..1cc5845 100644 --- a/jsquery.h +++ b/jsquery.h @@ -4,6 +4,7 @@ * Definitions of jsquery datatype * * Copyright (c) 2014, PostgreSQL Global Development Group + * Portions Copyright (c) 2017-2021, Postgres Professional * Author: Teodor Sigaev * * IDENTIFICATION diff --git a/jsquery_constr.c b/jsquery_constr.c index 19b0878..bfd0468 100644 --- a/jsquery_constr.c +++ b/jsquery_constr.c @@ -4,6 +4,7 @@ * Functions and operations to manipulate jsquery * * Copyright (c) 2014, PostgreSQL Global Development Group + * Portions Copyright (c) 2017-2021, Postgres Professional * Author: Teodor Sigaev * * IDENTIFICATION diff --git a/jsquery_extract.c b/jsquery_extract.c index 20da440..7d8a0ec 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -4,6 +4,7 @@ * Functions and operations to support jsquery in indexes * * Copyright (c) 2014, PostgreSQL Global Development Group + * Portions Copyright (c) 2017-2021, Postgres Professional * Author: Alexander Korotkov * * IDENTIFICATION diff --git a/jsquery_gram.y b/jsquery_gram.y index 282f2dc..21bcfb0 100644 --- a/jsquery_gram.y +++ b/jsquery_gram.y @@ -4,6 +4,7 @@ * Grammar definitions for jsquery datatype * * Copyright (c) 2014, PostgreSQL Global Development Group + * Portions Copyright (c) 2017-2021, Postgres Professional * Author: Teodor Sigaev * * IDENTIFICATION diff --git a/jsquery_op.c b/jsquery_op.c index ee61f8e..29cfe3d 100644 --- a/jsquery_op.c +++ b/jsquery_op.c @@ -4,6 +4,7 @@ * Functions and operations over jsquery/jsonb datatypes * * Copyright (c) 2014, PostgreSQL Global Development Group + * Portions Copyright (c) 2017-2021, Postgres Professional * Author: Teodor Sigaev * * IDENTIFICATION diff --git a/jsquery_scan.l b/jsquery_scan.l index 65bd6ba..3c7f2dd 100644 --- a/jsquery_scan.l +++ b/jsquery_scan.l @@ -4,6 +4,7 @@ * Lexical parser for jsquery datatype * * Copyright (c) 2014, PostgreSQL Global Development Group + * Portions Copyright (c) 2017-2021, Postgres Professional * Author: Teodor Sigaev * * IDENTIFICATION diff --git a/jsquery_support.c b/jsquery_support.c index 196956a..747776b 100644 --- a/jsquery_support.c +++ b/jsquery_support.c @@ -4,6 +4,7 @@ * Functions and operations to support jsquery * * Copyright (c) 2014, PostgreSQL Global Development Group + * Portions Copyright (c) 2017-2021, Postgres Professional * Author: Teodor Sigaev * * IDENTIFICATION From e45ff3833c4d022b8c055b90a7b254c1038d5f6b Mon Sep 17 00:00:00 2001 From: Marina Polyakova Date: Wed, 29 Jun 2022 17:15:13 +0300 Subject: [PATCH 47/53] PGPRO-6864: do not use the function pg_atoi if possible In PostgreSQL version 12 or higher it's more effecient to use the function pg_strtoint32 instead (see the commit 86eaf208ea048936df6be77276a246d3f92e9620). And in PostgreSQL 15 the function pg_atoi was removed altogether (see the commit 73508475d69e90f98ebd9b7e1a5933a26a49c5e9). Therefore if possible use the function pg_strtoint32 instead. --- jsquery_gram.y | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jsquery_gram.y b/jsquery_gram.y index 21bcfb0..84621e1 100644 --- a/jsquery_gram.y +++ b/jsquery_gram.y @@ -71,7 +71,11 @@ makeIndexArray(string *s) { JsQueryParseItem* v = makeItemType(jqiIndexArray); +#if PG_VERSION_NUM >= 120000 + v->arrayIndex = pg_strtoint32(s->val); +#else v->arrayIndex = pg_atoi(s->val, 4, 0); +#endif return v; } From 40b1db58b3f3f4b315a6f606ba88752c0f8b6aaf Mon Sep 17 00:00:00 2001 From: Marina Polyakova Date: Fri, 18 Nov 2022 07:23:48 +0300 Subject: [PATCH 48/53] Fix build due to new checks in PostgreSQL 16 The macro PG_DETOAST_DATUM returns a pointer to a varlena structure and the input to the function DatumGetPointer must be of type Datum (see the commit c8b2ef05f481ef06326d7b9f3eb14b303f215c7e in PostgreSQL 16). So use a simple cast instead of the function DatumGetPointer. --- jsquery.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsquery.h b/jsquery.h index 1cc5845..86226eb 100644 --- a/jsquery.h +++ b/jsquery.h @@ -26,7 +26,7 @@ typedef struct int32 vl_len_; /* varlena header (do not touch directly!) */ } JsQuery; -#define DatumGetJsQueryP(d) ((JsQuery*)DatumGetPointer(PG_DETOAST_DATUM(d))) +#define DatumGetJsQueryP(d) ((JsQuery*) PG_DETOAST_DATUM(d)) #define PG_GETARG_JSQUERY(x) DatumGetJsQueryP(PG_GETARG_DATUM(x)) #define PG_RETURN_JSQUERY(p) PG_RETURN_POINTER(p) From e76dfbfaa40d8e87116588dfa4c53e7fc552e953 Mon Sep 17 00:00:00 2001 From: Ekaterina Sokolova Date: Wed, 11 Oct 2023 22:33:06 +0300 Subject: [PATCH 49/53] [PGPRO-8962] Fix compilation errors via clang-15. 1) remove unused variable 2) suppress error about unused yynerr (bison variable) Tags: jsquery. --- jsonb_gin_ops.c | 2 -- jsquery_gram.y | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/jsonb_gin_ops.c b/jsonb_gin_ops.c index c63cad4..9a72c20 100644 --- a/jsonb_gin_ops.c +++ b/jsonb_gin_ops.c @@ -173,7 +173,6 @@ get_bloom_value(uint32 hash) static uint32 get_path_bloom(PathHashStack *stack) { - int i = 0; uint32 res = 0, val; while (stack) @@ -183,7 +182,6 @@ get_path_bloom(PathHashStack *stack) val = get_bloom_value(hash); res |= val; - i++; stack = stack->parent; } return res; diff --git a/jsquery_gram.y b/jsquery_gram.y index 84621e1..b6a4978 100644 --- a/jsquery_gram.y +++ b/jsquery_gram.y @@ -254,7 +254,10 @@ makeItemList(List *list) { %% result: - expr { *result = $1; } + expr { + *result = $1; + (void) yynerrs; /* suppress compiler warning */ + } | /* EMPTY */ { *result = NULL; } ; From 8011ac530523ced4ae9580776c6111b33378c142 Mon Sep 17 00:00:00 2001 From: Svetlana Derevyanko Date: Tue, 14 Nov 2023 10:25:41 +0300 Subject: [PATCH 50/53] [PGPRO-9047] Fixed parsing empty string into NULL Tags: jsquery --- expected/jsquery.out | 5 +++++ expected/jsquery_1.out | 5 +++++ jsquery_gram.y | 4 +++- jsquery_io.c | 13 ++++--------- jsquery_scan.l | 2 +- sql/jsquery.sql | 1 + 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/expected/jsquery.out b/expected/jsquery.out index 6767433..8c8d3b1 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -3,6 +3,11 @@ set escape_string_warning=off; set standard_conforming_strings=on; CREATE TABLE test_jsquery (v jsonb); \copy test_jsquery from 'data/test_jsquery.data' +select ''::jsquery; +ERROR: bad jsquery representation +LINE 1: select ''::jsquery; + ^ +DETAIL: No symbols read at the end of input select 'asd.zzz = 13'::jsquery; jsquery ------------------ diff --git a/expected/jsquery_1.out b/expected/jsquery_1.out index a265cc9..ea1f6dc 100644 --- a/expected/jsquery_1.out +++ b/expected/jsquery_1.out @@ -3,6 +3,11 @@ set escape_string_warning=off; set standard_conforming_strings=on; CREATE TABLE test_jsquery (v jsonb); \copy test_jsquery from 'data/test_jsquery.data' +select ''::jsquery; +ERROR: bad jsquery representation +LINE 1: select ''::jsquery; + ^ +DETAIL: No symbols read at the end of input select 'asd.zzz = 13'::jsquery; jsquery ------------------ diff --git a/jsquery_gram.y b/jsquery_gram.y index b6a4978..fd05e7a 100644 --- a/jsquery_gram.y +++ b/jsquery_gram.y @@ -258,7 +258,9 @@ result: *result = $1; (void) yynerrs; /* suppress compiler warning */ } - | /* EMPTY */ { *result = NULL; } + | /* EMPTY */ { + *result = NULL; + yyerror(NULL, "No symbols read"); } ; array: diff --git a/jsquery_io.c b/jsquery_io.c index ec44d5c..8a4b9ac 100644 --- a/jsquery_io.c +++ b/jsquery_io.c @@ -162,17 +162,12 @@ jsquery_in(PG_FUNCTION_ARGS) appendStringInfoSpaces(&buf, VARHDRSZ); - if (jsquery != NULL) - { - flattenJsQueryParseItem(&buf, jsquery, false); - - res = (JsQuery*)buf.data; - SET_VARSIZE(res, buf.len); + flattenJsQueryParseItem(&buf, jsquery, false); - PG_RETURN_JSQUERY(res); - } + res = (JsQuery*)buf.data; + SET_VARSIZE(res, buf.len); - PG_RETURN_NULL(); + PG_RETURN_JSQUERY(res); } static void diff --git a/jsquery_scan.l b/jsquery_scan.l index 3c7f2dd..f145650 100644 --- a/jsquery_scan.l +++ b/jsquery_scan.l @@ -206,7 +206,7 @@ yyerror(JsQueryParseItem **result, const char *message) (errcode(ERRCODE_SYNTAX_ERROR), errmsg("bad jsquery representation"), /* translator: %s is typically "syntax error" */ - errdetail("%s at end of input", message))); + errdetail("%s at the end of input", message))); } else { diff --git a/sql/jsquery.sql b/sql/jsquery.sql index 0b50dbe..d183741 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -7,6 +7,7 @@ CREATE TABLE test_jsquery (v jsonb); \copy test_jsquery from 'data/test_jsquery.data' +select ''::jsquery; select 'asd.zzz = 13'::jsquery; select 'asd.zzz < 13'::jsquery; select 'asd(zzz < 13)'::jsquery; From 8bc077da0b4f24158059b42e47caeee3fd1cb1bf Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Wed, 24 Aug 2016 18:25:16 -0500 Subject: [PATCH 51/53] Grammatical fixes. --- README.md | 174 +++++++++++++++++++++++++++--------------------------- 1 file changed, 86 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 7b15ae0..96e6274 100644 --- a/README.md +++ b/README.md @@ -84,28 +84,27 @@ Simple expression is specified as `path binary_operator value` or than 5; * `similar_product_ids.# = "0684824396"` – array "similar\_product\_ids" contains string "0684824396". - * `*.color = "red"` – there is object somewhere which key "color" has value - "red". + * `*.color = "red"` – there is object somewhere which key "color" has value "red". * `foo = *` – key "foo" exists in object. -Path selects set of JSON values to be checked using given operators. In -the simplest case path is just an key name. In general path is key names and -placeholders combined by dot signs. Path can use following placeholders: +Path selects a set of JSON values to be checked using given operators. In +the simplest case path is just a key name. In general path is key names and +placeholders combined by dot signs. Path can use the following placeholders: - * `#` – any index of array; - * `#N` – N-th index of array; - * `%` – any key of object; + * `#` – any index of an array; + * `#N` – N-th index of an array; + * `%` – any key of an object; * `*` – any sequence of array indexes and object keys; - * `@#` – length of array or object, could be only used as last component of - path; - * `$` – the whole JSON document as single value, could be only the whole path. + * `@#` – length of array or object, may only be used as the last component of + a path; + * `$` – the whole JSON document as single value, may only be the whole path. Expression is true when operator is true against at least one value selected by path. Key names could be given either with or without double quotes. Key names -without double quotes shouldn't contain spaces, start with number or concur -with jsquery keyword. +without double quotes may not contain spaces, start with a number or match +a jsquery keyword. The supported binary operators are: @@ -121,78 +120,77 @@ The supported unary operators are: * Check for type operators: `IS ARRAY`, `IS NUMERIC`, `IS OBJECT`, `IS STRING` and `IS BOOLEAN`. -Expressions could be complex. Complex expression is a set of expressions +Expressions can be complex. Complex expression is a set of expressions combined by logical operators (`AND`, `OR`, `NOT`) and grouped using braces. -Examples of complex expressions are given below. +Examples of complex expressions: * `a = 1 AND (b = 2 OR c = 3) AND NOT d = 1` * `x.% = true OR x.# = true` -Prefix expressions are expressions given in the form path (subexpression). -In this case path selects JSON values to be checked using given subexpression. +Prefix expressions are expressions given in the form `path (subexpression)`. +In this case path selects JSON values to be checked using the given subexpression. Check results are aggregated in the same way as in simple expressions. * `#(a = 1 AND b = 2)` – exists element of array which a key is 1 and b key is 2 * `%($ >= 10 AND $ <= 20)` – exists object key which values is between 10 and 20 -Path also could contain following special placeholders with "every" semantics: +Path can also contain the following special placeholders with "every" semantics: - * `#:` – every indexes of array; - * `%:` – every key of object; + * `#:` – every index of an array; + * `%:` – every key of an object; * `*:` – every sequence of array indexes and object keys. Consider following example. %.#:($ >= 0 AND $ <= 1) -This example could be read as following: there is at least one key which value -is array of numerics between 0 and 1. +This example could be read as following: there is at least one key whose value +is an array of numerics between 0 and 1. -We can rewrite this example in the following form with extra braces. +We can rewrite this example in the following form with extra braces: %(#:($ >= 0 AND $ <= 1)) -The first placeholder `%` checks that expression in braces is true for at least -one value in object. The second placeholder `#:` checks value to be array and -all its elements satisfy expressions in braces. +The first placeholder `%` checks that the expression in braces is true for at least +one value in the object. The second placeholder `#:` checks if the value is an array +and that all its elements satisfy the expressions in braces. -We can rewrite this example without `#:` placeholder as follows. +We can rewrite this example without the `#:` placeholder as follows: %(NOT #(NOT ($ >= 0 AND $ <= 1)) AND $ IS ARRAY) -In this example we transform assertion that every element of array satisfy some -condition to assertion that there is no one element which doesn't satisfy the -same condition. +In this example we transform the assertion that every element of array satisfy some +condition to an assertion that there are no elements which don't satisfy the same +condition. -Some examples of using paths are given below. +Some examples of using paths: * `numbers.#: IS NUMERIC` – every element of "numbers" array is numeric. * `*:($ IS OBJECT OR $ IS BOOLEAN)` – JSON is a structure of nested objects with booleans as leaf values. - * `#:.%:($ >= 0 AND $ <= 1)` – each element of array is object containing + * `#:.%:($ >= 0 AND $ <= 1)` – each element of array is an object containing only numeric values between 0 and 1. - * `documents.#:.% = *` – "documents" is array of objects containing at least + * `documents.#:.% = *` – "documents" is an array of objects containing at least one key. * `%.#: ($ IS STRING)` – JSON object contains at least one array of strings. - * `#.% = true` – at least one array element is objects which contains at least + * `#.% = true` – at least one array element is an object which contains at least one "true" value. -Usage of path operators and braces need some explanation. When same path -operators are used multiple times they may refer different values while you can -refer same value multiple time by using braces and `$` operator. See following -examples. +The use of path operators and braces need some further explanation. When the same path +operators are used multiple times, they may refer to different values. If you want them +to always refer to the same value, you must use braces and the `$` operator. For example: - * `# < 10 AND # > 20` – exists element less than 10 and exists another element - greater than 20. - * `#($ < 10 AND $ > 20)` – exists element which both less than 10 and greater - than 20 (impossible). - * `#($ >= 10 AND $ <= 20)` – exists element between 10 and 20. - * `# >= 10 AND # <= 20` – exists element great or equal to 10 and exists - another element less or equal to 20. Query can be satisfied by array with - no elements between 10 and 20, for instance [0,30]. + * `# < 10 AND # > 20` – an element less than 10 exists, and another element + greater than 20 exists. + * `#($ < 10 AND $ > 20)` – an element which is both less than 10 and greater + than 20 exists (impossible). + * `#($ >= 10 AND $ <= 20)` – an element between 10 and 20 exists. + * `# >= 10 AND # <= 20` – an element greater or equal to 10 exists, and another + element less or equal to 20 exists. Please note that this query also can be + satisfied by an array with no elements between 10 and 20, for instance [0,30]. -Same rules apply when you search inside objects and branchy structures. +Same rules apply when searching inside objects and branch structures. Type checking operators and "every" placeholders are useful for document schema validation. JsQuery matchig operator `@@` is immutable and can be used @@ -208,9 +206,9 @@ CREATE TABLE js ( points.#:(x IS NUMERIC AND y IS NUMERIC)'::jsquery)); ``` -In this example check constraint validates that in "data" jsonb column: -value of "name" key is string, value of "similar_ids" key is array of numerics, -value of "points" key is array of objects which contain numeric values in +In this example the check constraint validates that in the "data" jsonb column +the value of the "name" key is a string, the value of the "similar_ids" key is an array of numerics, +and the value of the "points" key is an array of objects which contain numeric values in "x" and "y" keys. See our @@ -227,11 +225,11 @@ provide different kinds of query optimization. * jsonb\_value\_path\_ops In each of two GIN opclasses jsonb documents are decomposed into entries. Each -entry is associated with particular value and it's path. Difference between +entry is associated with a particular value and its path. The difference between opclasses is in the entry representation, comparison and usage for search optimization. -For example, jsonb document +For example, the jsonb document `{"a": [{"b": "xyz", "c": true}, 10], "d": {"e": [7, false]}}` would be decomposed into following entries: @@ -241,57 +239,57 @@ would be decomposed into following entries: * "d"."e".#.7 * "d"."e".#.false -Since JsQuery doesn't support search in particular array index, we consider +Since JsQuery doesn't support searching in a particular array index, we consider all array elements to be equivalent. Thus, each array element is marked with -same `#` sign in the path. +the same `#` sign in its path. Major problem in the entries representation is its size. In the given example -key "a" is presented three times. In the large branchy documents with long -keys size of naive entries representation becomes unreasonable. Both opclasses -address this issue but in a slightly different way. +the key "a" is presented three times. In large branchy documents with long +keys sizes of naive entries, the representation becomes unreasonably large. +Both opclasses address this issue, but in slightly different ways. ### jsonb\_path\_value\_ops jsonb\_path\_value\_ops represents entry as pair of path hash and value. -Following pseudocode illustrates it. +Following pseudocode illustrates it: (hash(path_item_1.path_item_2. ... .path_item_n); value) -In comparison of entries path hash is the higher part of entry and value is -its lower part. This determines the features of this opclass. Since path -is hashed and it is higher part of entry we need to know the full path to -the value in order to use it for search. However, once path is specified +When comparison entries, the path hash is the higher part of entry and the value is +the lower part. This determines the features of this opclass. Since the path +is hashed and it's the higher part of the entry, we need to know the full path to +a value in order to use the it for searching. However, once the path is specified we can use both exact and range searches very efficiently. ### jsonb\_value\_path\_ops -jsonb\_value\_path\_ops represents entry as pair of value and bloom filter -of path. +jsonb\_value\_path\_ops represents entry as pair of the value and a bloom filter +of paths: (value; bloom(path_item_1) | bloom(path_item_2) | ... | bloom(path_item_n)) In comparison of entries value is the higher part of entry and bloom filter of path is its lower part. This determines the features of this opclass. Since -value is the higher part of entry we can perform only exact value search -efficiently. Range value search is possible as well but we would have to -filter all the the different paths where matching values occur. Bloom filter -over path items allows index usage for conditions containing `%` and `*` in +the value is the higher part of an entry, we can only perform exact value search +effectively. A search over a range of values is possible as well, but we have to +filter all the the different paths where matching values occur. The Bloom filter +over path items allows the index to be used for conditions containing `%` and `*` in their paths. ### Query optimization -JsQuery opclasses perform complex query optimization. Thus it's valuable for +JsQuery opclasses perform complex query optimization. It's valuable for a developer or administrator to see the result of such optimization. -Unfortunately, opclasses aren't allowed to do any custom output to the -EXPLAIN. That's why JsQuery provides following functions which allows to see -how particular opclass optimizes given query. +Unfortunately, opclasses aren't allowed to put any custom output in an +EXPLAIN. That's why JsQuery provides these functions to let you see +how particular opclass optimizes given query: * gin\_debug\_query\_path\_value(jsquery) – for jsonb\_path\_value\_ops * gin\_debug\_query\_value\_path(jsquery) – for jsonb\_value\_path\_ops -Result of these functions is a textual representation of query tree which -leafs are GIN search entries. Following examples show different results of -query optimization by different opclasses. +The result of these functions is a textual representation of the query tree +where leaves are GIN search entries. Following examples show different results of +query optimization by different opclasses: # SELECT gin_debug_query_path_value('x = 1 AND (*.y = 1 OR y = 2)'); gin_debug_query_path_value @@ -309,9 +307,9 @@ query optimization by different opclasses. Unfortunately, jsonb have no statistics yet. That's why JsQuery optimizer has to do imperative decision while selecting conditions to be evaluated using -index. This decision is made by assumtion that some condition types are less -selective than others. Optimizer divides conditions into following selectivity -class (listed by descending of selectivity). +index. This decision is made by assuming that some condition types are less +selective than others. The optimizer divides conditions into following selectivity +classes (listed in descending order of selectivity): 1. Equality (x = c) 2. Range (c1 < x < c2) @@ -319,19 +317,19 @@ class (listed by descending of selectivity). 4. Is (x is type) 5. Any (x = \*) -Optimizer evades index evaluation of less selective conditions when possible. +The optimizer avoids index evaluation of less selective conditions when possible. For example, in the `x = 1 AND y > 0` query `x = 1` is assumed to be more -selective than `y > 0`. That's why index isn't used for evaluation of `y > 0`. +selective than `y > 0`. That's why the index isn't used for evaluation of `y > 0`. # SELECT gin_debug_query_path_value('x = 1 AND y > 0'); gin_debug_query_path_value ---------------------------- x = 1 , entry 0 + -With lack of statistics decisions made by optimizer can be inaccurate. That's -why JsQuery supports hints. Comments `/*-- index */` and `/*-- noindex */` -placed in the conditions forces optimizer to use and not use index -correspondingly. +With the lack of statistics, decisions made by optimizer can be inaccurate. That's +why JsQuery supports hints. The comments `/*-- index */` or `/*-- noindex */` +placed in the conditions force the optimizer to use or not use an index +correspondingly: SELECT gin_debug_query_path_value('x = 1 AND y /*-- index */ > 0'); gin_debug_query_path_value @@ -348,11 +346,11 @@ correspondingly. Contribution ------------ -Please, notice, that JsQuery is still under development and while it's -stable and tested, it may contains some bugs. Don't hesitate to raise +Please note that JsQuery is still under development. While it's +stable and tested, it may contain some bugs. Don't hesitate to create [issues at github](https://github.com/postgrespro/jsquery/issues) with your bug reports. -If you're lacking of some functionality in JsQuery and feeling power to -implement it then you're welcome to make pull requests. +If there's some functionality you'd like to see added to JsQuery and you feel +like you can implement it, then you're welcome to make pull requests. From cbbea144ba3c87b4266409cf1c5f4d5a3d7e0470 Mon Sep 17 00:00:00 2001 From: Ekaterina Sokolova Date: Thu, 7 Mar 2024 14:40:24 +0300 Subject: [PATCH 52/53] [PGPRO-9837] Remove unreachable code. Tags: jsquery. --- jsquery_extract.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/jsquery_extract.c b/jsquery_extract.c index 7d8a0ec..4517706 100644 --- a/jsquery_extract.c +++ b/jsquery_extract.c @@ -873,8 +873,6 @@ execRecursiveTristate(ExtractedNode *node, GinTernaryValue *check) v = execRecursiveTristate(node->args.items[i], check); if (v == GIN_FALSE) return GIN_FALSE; - else if (v == GIN_MAYBE) - res = GIN_MAYBE; } return res; case eOr: @@ -884,8 +882,6 @@ execRecursiveTristate(ExtractedNode *node, GinTernaryValue *check) v = execRecursiveTristate(node->args.items[i], check); if (v == GIN_TRUE) return GIN_TRUE; - else if (v == GIN_MAYBE) - res = GIN_MAYBE; } return res; default: From 40db5e12652f63668e4f2c11f4dc67b5bd8c34c3 Mon Sep 17 00:00:00 2001 From: Zharkov Roman Date: Tue, 21 Jan 2025 14:55:43 +0300 Subject: [PATCH 53/53] Add meson.build file to support building from the contrib source tree. --- meson.build | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 meson.build diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..10f4ee9 --- /dev/null +++ b/meson.build @@ -0,0 +1,53 @@ +# Copyright (c) 2025, Postgres Professional + +# Does not support the PGXS infrastructure at this time. Please, compile as part +# of the contrib source tree. + +jsquery_sources = files( + 'jsonb_gin_ops.c', + 'jsquery_constr.c', + 'jsquery_extract.c', + 'jsquery_io.c', + 'jsquery_op.c', + 'jsquery_support.c', +) + +jsquery_gram = custom_target('jsquerygram', + input: 'jsquery_gram.y', + kwargs: bison_kw, +) +generated_sources += jsquery_gram.to_list() +jsquery_sources += jsquery_gram + +run_command(flex, '--outfile=jsquery_scan.c', 'jsquery_scan.l', check: true) + +if host_system == 'windows' + jsquery_sources += rc_lib_gen.process(win32ver_rc, extra_args: [ + '--NAME', 'jsquery', + '--FILEDESC', 'jsquery - language to query jsonb data type.',]) +endif + +jsquery = shared_module('jsquery', + jsquery_sources, + include_directories: include_directories('.'), + kwargs: contrib_mod_args, +) +contrib_targets += jsquery + +install_data( + 'jsquery.control', + 'jsquery--1.0--1.1.sql', + 'jsquery--1.1.sql', + kwargs: contrib_data_args, +) + +tests += { + 'name': 'jsquery', + 'sd': meson.current_source_dir(), + 'bd': meson.current_build_dir(), + 'regress': { + 'sql': [ + 'jsquery', + ], + }, +} 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