From 5ec2b2281c1a25e9bb9f3c1104600db211c19a9f Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Wed, 5 Sep 2018 14:51:15 +0300 Subject: [PATCH 01/23] 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 02/23] 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 03/23] 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 04/23] 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 05/23] 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 06/23] 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 07/23] 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 08/23] 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 09/23] 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 10/23] 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 11/23] 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 12/23] 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 13/23] 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 14/23] [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 15/23] 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 16/23] 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 17/23] 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 18/23] 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 19/23] [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 20/23] [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 21/23] 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 22/23] [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 23/23] 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', + ], + }, +}