high cardinality across all documents, defining an index as
follows is an effective approach to indexing:
<programlisting>
+-- Note that the "jsonb -> text" operator can only be called on an
+-- object, and as a consequence the root "jdoc" datum must be an
+-- object. This is enforced during insertion.
CREATE INDEX idxgin ON api USING GIN ((jdoc -> 'tags'));
</programlisting>
</para>
bool skipNested = false;
JsonbIterator *it;
JsonbValue v;
- int r = 0;
+ int r;
if (JB_ROOT_IS_SCALAR(jb))
ereport(ERROR,
int klen = strlen(key);
JsonbIterator *it;
JsonbValue v;
- int r = WJB_DONE;
+ int r;
bool skipNested = false;
if (JB_ROOT_IS_SCALAR(jb))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("cannot call jsonb_object_field on a scalar")));
+ errmsg("cannot call jsonb_object_field (jsonb -> text operator) on a scalar")));
else if (JB_ROOT_IS_ARRAY(jb))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("cannot call jsonb_object_field on an array")));
+ errmsg("cannot call jsonb_object_field (jsonb -> text operator) on an array")));
Assert(JB_ROOT_IS_OBJECT(jb));
int klen = strlen(key);
JsonbIterator *it;
JsonbValue v;
- int r = 0;
+ int r;
bool skipNested = false;
if (JB_ROOT_IS_SCALAR(jb))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("cannot call jsonb_object_field_text on a scalar")));
+ errmsg("cannot call jsonb_object_field_text (jsonb ->> text operator) on a scalar")));
else if (JB_ROOT_IS_ARRAY(jb))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("cannot call jsonb_object_field_text on an array")));
+ errmsg("cannot call jsonb_object_field_text (jsonb ->> text operator) on an array")));
Assert(JB_ROOT_IS_OBJECT(jb));
int element = PG_GETARG_INT32(1);
JsonbIterator *it;
JsonbValue v;
- int r = WJB_DONE;
+ int r;
bool skipNested = false;
int element_number = 0;
if (JB_ROOT_IS_SCALAR(jb))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("cannot call jsonb_array_element on a scalar")));
+ errmsg("cannot call jsonb_array_element (jsonb -> int operator) on a scalar")));
else if (JB_ROOT_IS_OBJECT(jb))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("cannot call jsonb_array_element on an object")));
+ errmsg("cannot call jsonb_array_element (jsonb -> int operator) on an object")));
Assert(JB_ROOT_IS_ARRAY(jb));
int element = PG_GETARG_INT32(1);
JsonbIterator *it;
JsonbValue v;
- int r = 0;
+ int r;
bool skipNested = false;
int element_number = 0;
bool skipNested = false;
JsonbIterator *it;
JsonbValue v;
- int r = 0;
+ int r;
if (!JB_ROOT_IS_OBJECT(jb))
ereport(ERROR,
bool skipNested = false;
JsonbIterator *it;
JsonbValue v;
- int r = 0;
+ int r;
if (JB_ROOT_IS_SCALAR(jb))
ereport(ERROR,
('array','["zero", "one","two",null,"four","five"]'),
('object','{"field1":"val1","field2":"val2","field3":null}');
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'scalar';
-ERROR: cannot call jsonb_object_field on a scalar
+ERROR: cannot call jsonb_object_field (jsonb -> text operator) on a scalar
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'array';
-ERROR: cannot call jsonb_object_field on an array
+ERROR: cannot call jsonb_object_field (jsonb -> text operator) on an array
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'object';
?column?
----------
(1 row)
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'scalar';
-ERROR: cannot call jsonb_object_field_text on a scalar
+ERROR: cannot call jsonb_object_field_text (jsonb ->> text operator) on a scalar
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'array';
-ERROR: cannot call jsonb_object_field_text on an array
+ERROR: cannot call jsonb_object_field_text (jsonb ->> text operator) on an array
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object';
?column?
----------
(1 row)
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'scalar';
-ERROR: cannot call jsonb_array_element on a scalar
+ERROR: cannot call jsonb_array_element (jsonb -> int operator) on a scalar
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'array';
?column?
----------
(1 row)
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'object';
-ERROR: cannot call jsonb_array_element on an object
+ERROR: cannot call jsonb_array_element (jsonb -> int operator) on an object
SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'scalar';
ERROR: cannot call jsonb_array_element_text on a scalar
SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'array';
(1 row)
SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}'::jsonb -> 0; --expecting error
-ERROR: cannot call jsonb_array_element on an object
+ERROR: cannot call jsonb_array_element (jsonb -> int operator) on an object
SELECT '["a","b","c",[1,2],null]'::jsonb -> 0;
?column?
----------
('array','["zero", "one","two",null,"four","five"]'),
('object','{"field1":"val1","field2":"val2","field3":null}');
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'scalar';
-ERROR: cannot call jsonb_object_field on a scalar
+ERROR: cannot call jsonb_object_field (jsonb -> text operator) on a scalar
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'array';
-ERROR: cannot call jsonb_object_field on an array
+ERROR: cannot call jsonb_object_field (jsonb -> text operator) on an array
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'object';
?column?
----------
(1 row)
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'scalar';
-ERROR: cannot call jsonb_object_field_text on a scalar
+ERROR: cannot call jsonb_object_field_text (jsonb ->> text operator) on a scalar
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'array';
-ERROR: cannot call jsonb_object_field_text on an array
+ERROR: cannot call jsonb_object_field_text (jsonb ->> text operator) on an array
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object';
?column?
----------
(1 row)
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'scalar';
-ERROR: cannot call jsonb_array_element on a scalar
+ERROR: cannot call jsonb_array_element (jsonb -> int operator) on a scalar
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'array';
?column?
----------
(1 row)
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'object';
-ERROR: cannot call jsonb_array_element on an object
+ERROR: cannot call jsonb_array_element (jsonb -> int operator) on an object
SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'scalar';
ERROR: cannot call jsonb_array_element_text on a scalar
SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'array';
(1 row)
SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}'::jsonb -> 0; --expecting error
-ERROR: cannot call jsonb_array_element on an object
+ERROR: cannot call jsonb_array_element (jsonb -> int operator) on an object
SELECT '["a","b","c",[1,2],null]'::jsonb -> 0;
?column?
----------