{"world":"CAB", "org":21, "indexed":true, "line":988, "abstract":"ABC"}
{"title":"CBC", "status":66, "line":989}
{}
+{"array":["foo", "bar", "baz"]}
{"line":991, "abstract":"BA", "node":"BBB"}
{"line":992, "disabled":true, "pos":29, "public":false}
{"state":53, "wait":"CB", "subtitle":"CCC", "line":993, "date":"CAC", "public":false, "coauthors":"BB"}
{"wait":null, "line":1000}
{"age":25}
{"age":25.0}
-{}
\ No newline at end of file
+{}
t
(1 row)
+CREATE TABLE testjsonb (j jsonb);
+\copy testjsonb FROM 'data/jsonb.data'
-- containment
SELECT jsonb_contains('{"a":"b", "b":1, "c":null}', '{"a":"b"}');
jsonb_contains
t
(1 row)
+-- array exists - array elements should behave as keys
+SELECT 1 from testjsonb WHERE j->'array' ? 'bar';
+ ?column?
+----------
+ 1
+(1 row)
+
SELECT jsonb_exists_any('{"a":null, "b":"qq"}', ARRAY['a','b']);
jsonb_exists_any
------------------
(1 row)
-- indexing
-CREATE TABLE testjsonb (j jsonb);
-\copy testjsonb FROM 'data/jsonb.data'
SELECT count(*) FROM testjsonb WHERE j @> '{"wait":null}';
count
-------
42
(1 row)
+-- array exists - array elements should behave as keys (for index scans too)
+CREATE INDEX jidx_array ON testjsonb USING gist((j->'array'));
+SELECT 1 from testjsonb WHERE j->'array' ? 'bar';
+ ?column?
+----------
+ 1
+(1 row)
+
RESET enable_seqscan;
DROP INDEX jidx;
+DROP INDEX jidx_array;
CREATE INDEX jidx ON testjsonb USING gin (j);
SET enable_seqscan = off;
SELECT count(*) FROM testjsonb WHERE j @> '{"wait":null}';
SELECT count(*) FROM (SELECT (jsonb_each(j)).key FROM testjsonb) AS wow;
count
-------
- 4783
+ 4784
(1 row)
SELECT key, count(*) FROM (SELECT (jsonb_each(j)).key FROM testjsonb) AS wow GROUP BY key ORDER BY count DESC, key;
auth | 168
abstract | 161
age | 2
-(23 rows)
+ array | 1
+(24 rows)
-- sort/hash
SELECT count(distinct j) FROM testjsonb;
count
-------
- 886
+ 887
(1 row)
SET enable_hashagg = off;
SELECT count(*) FROM (SELECT j FROM (SELECT * FROM testjsonb UNION ALL SELECT * FROM testjsonb) js GROUP BY j) js2;
count
-------
- 886
+ 887
(1 row)
SET enable_hashagg = on;
SELECT count(*) FROM (SELECT j FROM (SELECT * FROM testjsonb UNION ALL SELECT * FROM testjsonb) js GROUP BY j) js2;
count
-------
- 886
+ 887
(1 row)
SELECT distinct * FROM (values (jsonb '{}' || ''),('{}')) v(j);
SELECT '{"x":"y"}'::jsonb <> '{"x":"y"}'::jsonb;
SELECT '{"x":"y"}'::jsonb <> '{"x":"z"}'::jsonb;
+CREATE TABLE testjsonb (j jsonb);
+\copy testjsonb FROM 'data/jsonb.data'
+
-- containment
SELECT jsonb_contains('{"a":"b", "b":1, "c":null}', '{"a":"b"}');
SELECT jsonb_contains('{"a":"b", "b":1, "c":null}', '{"a":"b", "c":null}');
SELECT jsonb '{"a":null, "b":"qq"}' ? 'b';
SELECT jsonb '{"a":null, "b":"qq"}' ? 'c';
SELECT jsonb '{"a":"null", "b":"qq"}' ? 'a';
+-- array exists - array elements should behave as keys
+SELECT 1 from testjsonb WHERE j->'array' ? 'bar';
SELECT jsonb_exists_any('{"a":null, "b":"qq"}', ARRAY['a','b']);
SELECT jsonb_exists_any('{"a":null, "b":"qq"}', ARRAY['b','a']);
SELECT jsonb '{ "a": "null \u0000 escape" }' ->> 'a' AS not_unescaped;
-- indexing
-CREATE TABLE testjsonb (j jsonb);
-\copy testjsonb FROM 'data/jsonb.data'
-
SELECT count(*) FROM testjsonb WHERE j @> '{"wait":null}';
SELECT count(*) FROM testjsonb WHERE j @> '{"wait":"CC"}';
SELECT count(*) FROM testjsonb WHERE j @> '{"wait":"CC", "public":true}';
SELECT count(*) FROM testjsonb WHERE j ? 'public';
SELECT count(*) FROM testjsonb WHERE j ?| ARRAY['public','disabled'];
SELECT count(*) FROM testjsonb WHERE j ?& ARRAY['public','disabled'];
+-- array exists - array elements should behave as keys (for index scans too)
+CREATE INDEX jidx_array ON testjsonb USING gist((j->'array'));
+SELECT 1 from testjsonb WHERE j->'array' ? 'bar';
RESET enable_seqscan;
DROP INDEX jidx;
+DROP INDEX jidx_array;
CREATE INDEX jidx ON testjsonb USING gin (j);
SET enable_seqscan = off;