[{"a": 1},{"b": [2, 3]}]
(1 row)
--- operators
--- @>
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b"}';
- ?column?
-----------
- t
-(1 row)
-
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "c":null}';
- ?column?
-----------
- t
-(1 row)
-
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "g":null}';
- ?column?
-----------
- f
-(1 row)
-
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"g":null}';
- ?column?
-----------
- f
-(1 row)
-
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"c"}';
- ?column?
-----------
- f
-(1 row)
-
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b"}';
- ?column?
-----------
- t
-(1 row)
-
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "c":"q"}';
- ?column?
-----------
- f
-(1 row)
-
-- jsonb extraction functions
CREATE TEMP TABLE test_jsonb (
json_type text,
t
(1 row)
+-- containment
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b"}';
+ ?column?
+----------
+ t
+(1 row)
+
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "c":null}';
+ ?column?
+----------
+ t
+(1 row)
+
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "g":null}';
+ ?column?
+----------
+ f
+(1 row)
+
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"g":null}';
+ ?column?
+----------
+ f
+(1 row)
+
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"c"}';
+ ?column?
+----------
+ f
+(1 row)
+
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b"}';
+ ?column?
+----------
+ t
+(1 row)
+
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "c":"q"}';
+ ?column?
+----------
+ f
+(1 row)
+
-- array length
SELECT jsonb_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]');
jsonb_array_length
-- make sure jsonb is passed through json generators without being escaped
select array_to_json(ARRAY [jsonb '{"a":1}', jsonb '{"b":[2,3]}']);
--- operators
-
--- @>
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b"}';
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "c":null}';
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "g":null}';
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"g":null}';
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"c"}';
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b"}';
-select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "c":"q"}';
-
-- jsonb extraction functions
CREATE TEMP TABLE test_jsonb (
select '{"x":"y"}'::jsonb <> '{"x":"y"}'::jsonb;
select '{"x":"y"}'::jsonb <> '{"x":"z"}'::jsonb;
+-- containment
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b"}';
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "c":null}';
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "g":null}';
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"g":null}';
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"c"}';
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b"}';
+select '{"a":"b", "b":1, "c":null}'::jsonb @> '{"a":"b", "c":"q"}';
+
-- array length
SELECT jsonb_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]');