Registering pre-existing tables
testjsonb
-- Strings.
SELECT '""'::jsonb; -- OK.
SELECT $$''$$::jsonb; -- ERROR, single quotes are not allowed
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT $$''$$::jsonb; -- ERROR, single quotes are not allowed
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Token "'" is invalid.
CONTEXT: JSON data, line 1: '...
SELECT $$''$$::jsonb; -- ERROR, single quotes are not allowed
^
SELECT '"abc"'::jsonb; -- OK
SELECT '"abc'::jsonb; -- ERROR, quotes not closed
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '"abc'::jsonb; -- ERROR, quotes not closed
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Token ""abc" is invalid.
CONTEXT: JSON data, line 1: "abc
SELECT '"abc'::jsonb; -- ERROR, quotes not closed
^
SELECT '"abc
def"'::jsonb; -- ERROR, unescaped newline in string constant
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '"abc
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Character with value 0x0a must be escaped.
CONTEXT: JSON data, line 1: "abc
SELECT '"abc
^
SELECT '"\n\"\\"'::jsonb; -- OK, legal escapes
SELECT '"\v"'::jsonb; -- ERROR, not a valid JSON escape
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '"\v"'::jsonb; -- ERROR, not a valid JSON escape
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Escape sequence "\v" is invalid.
CONTEXT: JSON data, line 1: "\v...
SELECT '"\v"'::jsonb; -- ERROR, not a valid JSON escape
^
-- see json_encoding test for input with unicode escapes
-- Numbers.
SELECT '1'::jsonb; -- OK
SELECT '0'::jsonb; -- OK
SELECT '01'::jsonb; -- ERROR, not valid according to JSON spec
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '01'::jsonb; -- ERROR, not valid according to JSON spec
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Token "01" is invalid.
CONTEXT: JSON data, line 1: 01
SELECT '01'::jsonb; -- ERROR, not valid according to JSON spec
^
SELECT '0.1'::jsonb; -- OK
SELECT '9223372036854775808'::jsonb; -- OK, even though it's too large for int8
SELECT '1e100'::jsonb; -- OK
SELECT '1.3e100'::jsonb; -- OK
SELECT '1f2'::jsonb; -- ERROR
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '1f2'::jsonb; -- ERROR
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Token "1f2" is invalid.
CONTEXT: JSON data, line 1: 1f2
SELECT '1f2'::jsonb; -- ERROR
^
SELECT '0.x1'::jsonb; -- ERROR
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '0.x1'::jsonb; -- ERROR
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Token "0.x1" is invalid.
CONTEXT: JSON data, line 1: 0.x1
SELECT '0.x1'::jsonb; -- ERROR
^
SELECT '1.3ex100'::jsonb; -- ERROR
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '1.3ex100'::jsonb; -- ERROR
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Token "1.3ex100" is invalid.
CONTEXT: JSON data, line 1: 1.3ex100
SELECT '1.3ex100'::jsonb; -- ERROR
^
-- Arrays.
SELECT '[]'::jsonb; -- OK
SELECT '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'::jsonb; -- OK
SELECT '[1,2]'::jsonb; -- OK
SELECT '[1,2,]'::jsonb; -- ERROR, trailing comma
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '[1,2,]'::jsonb; -- ERROR, trailing comma
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected JSON value, but found "]".
CONTEXT: JSON data, line 1: [1,2,]
SELECT '[1,2,]'::jsonb; -- ERROR, trailing comma
^
SELECT '[1,2'::jsonb; -- ERROR, no closing bracket
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '[1,2'::jsonb; -- ERROR, no closing bracket
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: The input string ended unexpectedly.
CONTEXT: JSON data, line 1: [1,2
SELECT '[1,2'::jsonb; -- ERROR, no closing bracket
^
SELECT '[1,[2]'::jsonb; -- ERROR, no closing bracket
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '[1,[2]'::jsonb; -- ERROR, no closing bracket
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: The input string ended unexpectedly.
CONTEXT: JSON data, line 1: [1,[2]
SELECT '[1,[2]'::jsonb; -- ERROR, no closing bracket
^
-- Objects.
SELECT '{}'::jsonb; -- OK
SELECT '{"abc"}'::jsonb; -- ERROR, no value
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '{"abc"}'::jsonb; -- ERROR, no value
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected ":", but found "}".
CONTEXT: JSON data, line 1: {"abc"}
SELECT '{"abc"}'::jsonb; -- ERROR, no value
^
SELECT '{"abc":1}'::jsonb; -- OK
SELECT '{1:"abc"}'::jsonb; -- ERROR, keys must be strings
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '{1:"abc"}'::jsonb; -- ERROR, keys must be strings
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected string or "}", but found "1".
CONTEXT: JSON data, line 1: {1...
SELECT '{1:"abc"}'::jsonb; -- ERROR, keys must be strings
^
SELECT '{"abc",1}'::jsonb; -- ERROR, wrong separator
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '{"abc",1}'::jsonb; -- ERROR, wrong separator
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected ":", but found ",".
CONTEXT: JSON data, line 1: {"abc",...
SELECT '{"abc",1}'::jsonb; -- ERROR, wrong separator
^
SELECT '{"abc"=1}'::jsonb; -- ERROR, totally wrong separator
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '{"abc"=1}'::jsonb; -- ERROR, totally wrong separator
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Token "=" is invalid.
CONTEXT: JSON data, line 1: {"abc"=...
SELECT '{"abc"=1}'::jsonb; -- ERROR, totally wrong separator
^
SELECT '{"abc"::1}'::jsonb; -- ERROR, another wrong separator
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '{"abc"::1}'::jsonb; -- ERROR, another wrong separator
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected JSON value, but found ":".
CONTEXT: JSON data, line 1: {"abc"::...
SELECT '{"abc"::1}'::jsonb; -- ERROR, another wrong separator
^
SELECT '{"abc":1,"def":2,"ghi":[3,4],"hij":{"klm":5,"nop":[6]}}'::jsonb; -- OK
SELECT '{"abc":1:2}'::jsonb; -- ERROR, colon in wrong spot
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '{"abc":1:2}'::jsonb; -- ERROR, colon in wrong spot
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected "," or "}", but found ":".
CONTEXT: JSON data, line 1: {"abc":1:...
SELECT '{"abc":1:2}'::jsonb; -- ERROR, colon in wrong spot
^
SELECT '{"abc":1,3}'::jsonb; -- ERROR, no value
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '{"abc":1,3}'::jsonb; -- ERROR, no value
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected string, but found "3".
CONTEXT: JSON data, line 1: {"abc":1,3...
SELECT '{"abc":1,3}'::jsonb; -- ERROR, no value
^
-- Miscellaneous stuff.
SELECT 'true'::jsonb; -- OK
SELECT 'false'::jsonb; -- OK
SELECT 'null'::jsonb; -- OK
SELECT ' true '::jsonb; -- OK, even with extra whitespace
SELECT 'true false'::jsonb; -- ERROR, too many values
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT 'true false'::jsonb; -- ERROR, too many values
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected end of input, but found "false".
CONTEXT: JSON data, line 1: true false
SELECT 'true false'::jsonb; -- ERROR, too many values
^
SELECT 'true, false'::jsonb; -- ERROR, too many values
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT 'true, false'::jsonb; -- ERROR, too many values
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected end of input, but found ",".
CONTEXT: JSON data, line 1: true,...
SELECT 'true, false'::jsonb; -- ERROR, too many values
^
SELECT 'truf'::jsonb; -- ERROR, not a keyword
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT 'truf'::jsonb; -- ERROR, not a keyword
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Token "truf" is invalid.
CONTEXT: JSON data, line 1: truf
SELECT 'truf'::jsonb; -- ERROR, not a keyword
^
SELECT 'trues'::jsonb; -- ERROR, not a keyword
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT 'trues'::jsonb; -- ERROR, not a keyword
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Token "trues" is invalid.
CONTEXT: JSON data, line 1: trues
SELECT 'trues'::jsonb; -- ERROR, not a keyword
^
SELECT ''::jsonb; -- ERROR, no value
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT ''::jsonb; -- ERROR, no value
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: The input string ended unexpectedly.
CONTEXT: JSON data, line 1:
SELECT ''::jsonb; -- ERROR, no value
^
SELECT ' '::jsonb; -- ERROR, no value
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT ' '::jsonb; -- ERROR, no value
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: The input string ended unexpectedly.
CONTEXT: JSON data, line 1:
SELECT ' '::jsonb; -- ERROR, no value
^
-- Multi-line JSON input to check ERROR reporting
SELECT '{
"one": 1,
"two":"two",
"three":
true}'::jsonb; -- OK
SELECT '{
"one": 1,
"two":,"two", -- ERROR extraneous comma before field "two"
"three":
true}'::jsonb;
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '{
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected JSON value, but found ",".
CONTEXT: JSON data, line 3: "two":,...
SELECT '{
^
SELECT '{
"one": 1,
"two":"two",
"averyveryveryveryveryveryveryveryveryverylongfieldname":}'::jsonb;
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT '{
^
-stdin-::1:1: Fatal: ERROR: invalid input syntax for type json
DETAIL: Expected JSON value, but found "}".
CONTEXT: JSON data, line 4: ...yveryveryveryveryveryveryveryverylongfieldname":}
SELECT '{
^
-- ERROR missing value for last field
-- make sure jsonb is passed through json generators without being escaped
SELECT array_to_json(ARRAY [jsonb '{"a":1}', jsonb '{"b":[2,3]}']);
-- anyarray column
CREATE TEMP TABLE rows AS
SELECT x, 'txt' || x as y
FROM generate_series(1,3) AS x;
-stdin-:: Error: Parse Sql
-stdin-::1:1: Error: RawStmt: alternative is not implemented yet : 277
-- anyarray column
^
analyze rows;
-stdin-:: Error: Parse Sql
-stdin-::1:1: Error: RawStmt: alternative is not implemented yet : 275
analyze rows;
^
select attname, to_jsonb(histogram_bounds) histogram_bounds
from pg_stats
where tablename = 'rows' and
schemaname = pg_my_temp_schema()::regnamespace::text
order by 1;
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
select attname, to_jsonb(histogram_bounds) histogram_bounds
^
-stdin-::1:17: Error: At function: PgCall
select attname, to_jsonb(histogram_bounds) histogram_bounds
^
-stdin-::1:17: Error: Unable to find an overload for proc to_jsonb with given argument types: (anyarray)
select attname, to_jsonb(histogram_bounds) histogram_bounds
^
-- to_jsonb, timestamps
select to_jsonb(timestamp '2014-05-28 12:22:35.614298');
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
-- to_jsonb, timestamps
^
-stdin-::2:8: Error: At function: PgCall
select to_jsonb(timestamp '2014-05-28 12:22:35.614298');
^
-stdin-::2:8: Error: Unable to find an overload for proc to_jsonb with given argument types: (timestamp)
select to_jsonb(timestamp '2014-05-28 12:22:35.614298');
^
BEGIN;
SET LOCAL TIME ZONE 10.5;
select to_jsonb(timestamptz '2014-05-28 12:22:35.614298-04');
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
select to_jsonb(timestamptz '2014-05-28 12:22:35.614298-04');
^
-stdin-::1:8: Error: At function: PgCall
select to_jsonb(timestamptz '2014-05-28 12:22:35.614298-04');
^
-stdin-::1:8: Error: Unable to find an overload for proc to_jsonb with given argument types: (timestamptz)
select to_jsonb(timestamptz '2014-05-28 12:22:35.614298-04');
^
SET LOCAL TIME ZONE -8;
select to_jsonb(timestamptz '2014-05-28 12:22:35.614298-04');
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
select to_jsonb(timestamptz '2014-05-28 12:22:35.614298-04');
^
-stdin-::1:8: Error: At function: PgCall
select to_jsonb(timestamptz '2014-05-28 12:22:35.614298-04');
^
-stdin-::1:8: Error: Unable to find an overload for proc to_jsonb with given argument types: (timestamptz)
select to_jsonb(timestamptz '2014-05-28 12:22:35.614298-04');
^
COMMIT;
select to_jsonb(date '2014-05-28');
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
select to_jsonb(date '2014-05-28');
^
-stdin-::1:8: Error: At function: PgCall
select to_jsonb(date '2014-05-28');
^
-stdin-::1:8: Error: Unable to find an overload for proc to_jsonb with given argument types: (date)
select to_jsonb(date '2014-05-28');
^
select to_jsonb(date 'Infinity');
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
select to_jsonb(date 'Infinity');
^
-stdin-::1:8: Error: At function: PgCall
select to_jsonb(date 'Infinity');
^
-stdin-::1:8: Error: Unable to find an overload for proc to_jsonb with given argument types: (date)
select to_jsonb(date 'Infinity');
^
select to_jsonb(date '-Infinity');
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
select to_jsonb(date '-Infinity');
^
-stdin-::1:8: Error: At function: PgCall
select to_jsonb(date '-Infinity');
^
-stdin-::1:8: Error: Unable to find an overload for proc to_jsonb with given argument types: (date)
select to_jsonb(date '-Infinity');
^
select to_jsonb(timestamp 'Infinity');
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
select to_jsonb(timestamp 'Infinity');
^
-stdin-::1:8: Error: At function: PgCall
select to_jsonb(timestamp 'Infinity');
^
-stdin-::1:8: Error: Unable to find an overload for proc to_jsonb with given argument types: (timestamp)
select to_jsonb(timestamp 'Infinity');
^
select to_jsonb(timestamp '-Infinity');
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
select to_jsonb(timestamp '-Infinity');
^
-stdin-::1:8: Error: At function: PgCall
select to_jsonb(timestamp '-Infinity');
^
-stdin-::1:8: Error: Unable to find an overload for proc to_jsonb with given argument types: (timestamp)
select to_jsonb(timestamp '-Infinity');
^
select to_jsonb(timestamptz 'Infinity');
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
select to_jsonb(timestamptz 'Infinity');
^
-stdin-::1:8: Error: At function: PgCall
select to_jsonb(timestamptz 'Infinity');
^
-stdin-::1:8: Error: Unable to find an overload for proc to_jsonb with given argument types: (timestamptz)
select to_jsonb(timestamptz 'Infinity');
^
select to_jsonb(timestamptz '-Infinity');
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem, At function: PgResultItem
select to_jsonb(timestamptz '-Infinity');
^
-stdin-::1:8: Error: At function: PgCall
select to_jsonb(timestamptz '-Infinity');
^
-stdin-::1:8: Error: Unable to find an overload for proc to_jsonb with given argument types: (timestamptz)
select to_jsonb(timestamptz '-Infinity');
^
--jsonb_agg
SELECT jsonb_agg(q)
FROM ( SELECT $$a$$ || x AS b, y AS c,
ARRAY[ROW(x.*,ARRAY[1,2,3]),
ROW(y.*,ARRAY[4,5,6])] AS z
FROM generate_series(1,2) x,
generate_series(4,5) y) q;
-stdin-:: Error: Parse Sql
-stdin-::4:16: Error: alternative is not implemented yet : 138
ARRAY[ROW(x.*,ARRAY[1,2,3]),
^
-stdin-:: Error: Type annotation
-stdin-::1:1: Error: At function: RemovePrefixMembers, At function: PgSelect
--jsonb_agg
^
-stdin-::1:1: Error: Recursive query does not have the form non-recursive-term UNION [ALL] recursive-term
--jsonb_agg
^
SELECT jsonb_agg(q ORDER BY x, y)
FROM rows q;
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported agg_order
SELECT jsonb_agg(q ORDER BY x, y)
^
UPDATE rows SET x = NULL WHERE x = 1;
-stdin-:: Fatal: Pre type annotation
-stdin-:: Fatal: tools/enum_parser/enum_serialization_runtime/enum_runtime.cpp:70: Key 'pg_update' not found in enum NYql::EYtSettingType. Valid options are: 'initial', 'infer_scheme', 'force_infer_schema', 'do_not_fail_on_invalid_schema', 'direct_read', 'view', 'mode', 'scheme', 'weak_concat', 'anonymous', 'with_qb', 'inline', 'sample', 'joinLabel', 'ignore_non_existing', 'warn_non_existing', 'xlock', 'unordered', 'nonUnique', 'userschema', 'usercolumns', 'statcolumns', 'syscolumns', 'ignoretypev3', 'memUsage', 'itemsCount', 'rowFactor', 'ordered', 'keyFilter', 'keyFilter2', 'take', 'skip', 'limit', 'sortLimitBy', 'sortBy', 'reduceBy', 'reduceFilterBy', 'forceTransform', 'weakFields', 'sharded', 'combineChunks', 'jobCount', 'joinReduce', 'firstAsPrimary', 'flow', 'keepSorted', 'keySwitch', 'uniqueBy', 'opHash', 'mapOutputType', 'reduceInputType', 'noDq', 'split', 'compression_codec', 'erasure_codec', 'expiration', 'replication_factor', 'user_attrs', 'media', 'primary_medium', 'keep_meta', 'monotonic_keys', 'mutationid'.
SELECT jsonb_agg(q ORDER BY x NULLS FIRST, y)
FROM rows q;
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported agg_order
SELECT jsonb_agg(q ORDER BY x NULLS FIRST, y)
^
-- jsonb extraction functions
CREATE TEMP TABLE test_jsonb (
json_type text,
test_json jsonb
);
INSERT INTO test_jsonb VALUES
('scalar','"a scalar"'),
('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'),
('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}');
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'scalar';
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'array';
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'object';
SELECT test_json -> 'field2' FROM test_jsonb WHERE json_type = 'object';
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'scalar';
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'array';
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object';
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'scalar';
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'array';
SELECT test_json -> 9 FROM test_jsonb WHERE json_type = 'array';
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'object';
SELECT test_json ->> 6 FROM test_jsonb WHERE json_type = 'array';
SELECT test_json ->> 7 FROM test_jsonb WHERE json_type = 'array';
SELECT test_json ->> 'field4' FROM test_jsonb WHERE json_type = 'object';
SELECT test_json ->> 'field5' FROM test_jsonb WHERE json_type = 'object';
SELECT test_json ->> 'field6' FROM test_jsonb WHERE json_type = 'object';
SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'scalar';
SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'array';
SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'object';
SELECT jsonb_object_keys(test_json) FROM test_jsonb WHERE json_type = 'scalar';
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: Generator functions are not allowed in: SELECT
SELECT jsonb_object_keys(test_json) FROM test_jsonb WHERE json_type = 'scalar';
^
SELECT jsonb_object_keys(test_json) FROM test_jsonb WHERE json_type = 'array';
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: Generator functions are not allowed in: SELECT
SELECT jsonb_object_keys(test_json) FROM test_jsonb WHERE json_type = 'array';
^
SELECT jsonb_object_keys(test_json) FROM test_jsonb WHERE json_type = 'object';
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: Generator functions are not allowed in: SELECT
SELECT jsonb_object_keys(test_json) FROM test_jsonb WHERE json_type = 'object';
^
-- nulls
SELECT (test_json->'field3') IS NULL AS expect_false FROM test_jsonb WHERE json_type = 'object';
SELECT (test_json->>'field3') IS NULL AS expect_true FROM test_jsonb WHERE json_type = 'object';
SELECT (test_json->3) IS NULL AS expect_false FROM test_jsonb WHERE json_type = 'array';
SELECT (test_json->>3) IS NULL AS expect_true FROM test_jsonb WHERE json_type = 'array';
-- corner cases
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb -> null::text;
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb -> null::int;
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb -> 1;
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb -> 'z';
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb -> '';
select '[{"b": "c"}, {"b": "cc"}]'::jsonb -> 1;
select '[{"b": "c"}, {"b": "cc"}]'::jsonb -> 3;
select '[{"b": "c"}, {"b": "cc"}]'::jsonb -> 'z';
select '{"a": "c", "b": null}'::jsonb -> 'b';
select '"foo"'::jsonb -> 1;
select '"foo"'::jsonb -> 'z';
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> null::text;
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> null::int;
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> 1;
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> 'z';
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> '';
select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 1;
select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 3;
select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 'z';
select '{"a": "c", "b": null}'::jsonb ->> 'b';
select '"foo"'::jsonb ->> 1;
select '"foo"'::jsonb ->> 'z';
-- equality and inequality
SELECT '{"x":"y"}'::jsonb = '{"x":"y"}'::jsonb;
SELECT '{"x":"y"}'::jsonb = '{"x":"z"}'::jsonb;
SELECT '{"x":"y"}'::jsonb <> '{"x":"y"}'::jsonb;
SELECT '{"x":"y"}'::jsonb <> '{"x":"z"}'::jsonb;
-- 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_contains('{"a":"b", "b":1, "c":null}', '{"a":"b", "g":null}');
SELECT jsonb_contains('{"a":"b", "b":1, "c":null}', '{"g":null}');
SELECT jsonb_contains('{"a":"b", "b":1, "c":null}', '{"a":"c"}');
SELECT jsonb_contains('{"a":"b", "b":1, "c":null}', '{"a":"b"}');
SELECT jsonb_contains('{"a":"b", "b":1, "c":null}', '{"a":"b", "c":"q"}');
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"}';
SELECT '[1,2]'::jsonb @> '[1,2,2]'::jsonb;
SELECT '[1,1,2]'::jsonb @> '[1,2,2]'::jsonb;
SELECT '[[1,2]]'::jsonb @> '[[1,2,2]]'::jsonb;
SELECT '[1,2,2]'::jsonb <@ '[1,2]'::jsonb;
SELECT '[1,2,2]'::jsonb <@ '[1,1,2]'::jsonb;
SELECT '[[1,2,2]]'::jsonb <@ '[[1,2]]'::jsonb;
SELECT jsonb_contained('{"a":"b"}', '{"a":"b", "b":1, "c":null}');
SELECT jsonb_contained('{"a":"b", "c":null}', '{"a":"b", "b":1, "c":null}');
SELECT jsonb_contained('{"a":"b", "g":null}', '{"a":"b", "b":1, "c":null}');
SELECT jsonb_contained('{"g":null}', '{"a":"b", "b":1, "c":null}');
SELECT jsonb_contained('{"a":"c"}', '{"a":"b", "b":1, "c":null}');
SELECT jsonb_contained('{"a":"b"}', '{"a":"b", "b":1, "c":null}');
SELECT jsonb_contained('{"a":"b", "c":"q"}', '{"a":"b", "b":1, "c":null}');
SELECT '{"a":"b"}'::jsonb <@ '{"a":"b", "b":1, "c":null}';
SELECT '{"a":"b", "c":null}'::jsonb <@ '{"a":"b", "b":1, "c":null}';
SELECT '{"a":"b", "g":null}'::jsonb <@ '{"a":"b", "b":1, "c":null}';
SELECT '{"g":null}'::jsonb <@ '{"a":"b", "b":1, "c":null}';
SELECT '{"a":"c"}'::jsonb <@ '{"a":"b", "b":1, "c":null}';
SELECT '{"a":"b"}'::jsonb <@ '{"a":"b", "b":1, "c":null}';
SELECT '{"a":"b", "c":"q"}'::jsonb <@ '{"a":"b", "b":1, "c":null}';
-- Raw scalar may contain another raw scalar, array may contain a raw scalar
SELECT '[5]'::jsonb @> '[5]';
SELECT '5'::jsonb @> '5';
SELECT '[5]'::jsonb @> '5';
-- But a raw scalar cannot contain an array
SELECT '5'::jsonb @> '[5]';
-- In general, one thing should always contain itself. Test array containment:
SELECT '["9", ["7", "3"], 1]'::jsonb @> '["9", ["7", "3"], 1]'::jsonb;
SELECT '["9", ["7", "3"], ["1"]]'::jsonb @> '["9", ["7", "3"], ["1"]]'::jsonb;
-- array containment string matching confusion bug
SELECT '{ "name": "Bob", "tags": [ "enim", "qui"]}'::jsonb @> '{"tags":["qu"]}';
-- array length
SELECT jsonb_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]');
SELECT jsonb_array_length('[]');
SELECT jsonb_array_length('{"f1":1,"f2":[5,6]}');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_array_length('{"f1":1,"f2":[5,6]}');
^
-stdin-::1:1: Fatal: ERROR: cannot get array length of a non-array
SELECT jsonb_array_length('{"f1":1,"f2":[5,6]}');
^
SELECT jsonb_array_length('4');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_array_length('4');
^
-stdin-::1:1: Fatal: ERROR: cannot get array length of a scalar
SELECT jsonb_array_length('4');
^
-- each
SELECT jsonb_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null}');
-stdin-:: Error: Parse Sql
-stdin-::2:8: Error: Generator functions are not allowed in: SELECT
SELECT jsonb_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null}');
^
SELECT jsonb_each('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}'::jsonb) AS q;
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: Generator functions are not allowed in: SELECT
SELECT jsonb_each('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}'::jsonb) AS q;
^
SELECT * FROM jsonb_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q;
SELECT * FROM jsonb_each('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}'::jsonb) AS q;
SELECT jsonb_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":"null"}');
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: Generator functions are not allowed in: SELECT
SELECT jsonb_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":"null"}');
^
SELECT jsonb_each_text('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}'::jsonb) AS q;
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: Generator functions are not allowed in: SELECT
SELECT jsonb_each_text('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}'::jsonb) AS q;
^
SELECT * FROM jsonb_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q;
SELECT * FROM jsonb_each_text('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}'::jsonb) AS q;
-- exists
SELECT jsonb_exists('{"a":null, "b":"qq"}', 'a');
SELECT jsonb_exists('{"a":null, "b":"qq"}', 'b');
SELECT jsonb_exists('{"a":null, "b":"qq"}', 'c');
SELECT jsonb_exists('{"a":"null", "b":"qq"}', 'a');
SELECT jsonb '{"a":null, "b":"qq"}' ? 'a';
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 count(*) from testjsonb WHERE j->'array' ? 'bar';
-- type sensitive array exists - should return no rows (since "exists" only
-- matches strings that are either object keys or array elements)
SELECT count(*) from testjsonb WHERE j->'array' ? '5'::text;
-- However, a raw scalar is *contained* within the array
SELECT count(*) from testjsonb WHERE j->'array' @> '5'::jsonb;
SELECT jsonb_exists_any('{"a":null, "b":"qq"}', ARRAY['a','b']);
SELECT jsonb_exists_any('{"a":null, "b":"qq"}', ARRAY['b','a']);
SELECT jsonb_exists_any('{"a":null, "b":"qq"}', ARRAY['c','a']);
SELECT jsonb_exists_any('{"a":null, "b":"qq"}', ARRAY['c','d']);
SELECT jsonb_exists_any('{"a":null, "b":"qq"}', '{}'::text[]);
SELECT jsonb '{"a":null, "b":"qq"}' ?| ARRAY['a','b'];
SELECT jsonb '{"a":null, "b":"qq"}' ?| ARRAY['b','a'];
SELECT jsonb '{"a":null, "b":"qq"}' ?| ARRAY['c','a'];
SELECT jsonb '{"a":null, "b":"qq"}' ?| ARRAY['c','d'];
SELECT jsonb '{"a":null, "b":"qq"}' ?| '{}'::text[];
SELECT jsonb_exists_all('{"a":null, "b":"qq"}', ARRAY['a','b']);
SELECT jsonb_exists_all('{"a":null, "b":"qq"}', ARRAY['b','a']);
SELECT jsonb_exists_all('{"a":null, "b":"qq"}', ARRAY['c','a']);
SELECT jsonb_exists_all('{"a":null, "b":"qq"}', ARRAY['c','d']);
SELECT jsonb_exists_all('{"a":null, "b":"qq"}', '{}'::text[]);
SELECT jsonb '{"a":null, "b":"qq"}' ?& ARRAY['a','b'];
SELECT jsonb '{"a":null, "b":"qq"}' ?& ARRAY['b','a'];
SELECT jsonb '{"a":null, "b":"qq"}' ?& ARRAY['c','a'];
SELECT jsonb '{"a":null, "b":"qq"}' ?& ARRAY['c','d'];
SELECT jsonb '{"a":null, "b":"qq"}' ?& ARRAY['a','a', 'b', 'b', 'b'];
SELECT jsonb '{"a":null, "b":"qq"}' ?& '{}'::text[];
-- typeof
SELECT jsonb_typeof('{}') AS object;
SELECT jsonb_typeof('{"c":3,"p":"o"}') AS object;
SELECT jsonb_typeof('[]') AS array;
SELECT jsonb_typeof('["a", 1]') AS array;
SELECT jsonb_typeof('null') AS "null";
SELECT jsonb_typeof('1') AS number;
SELECT jsonb_typeof('-1') AS number;
SELECT jsonb_typeof('1.0') AS number;
SELECT jsonb_typeof('1e2') AS number;
SELECT jsonb_typeof('-1.0') AS number;
SELECT jsonb_typeof('true') AS boolean;
SELECT jsonb_typeof('false') AS boolean;
SELECT jsonb_typeof('"hello"') AS string;
SELECT jsonb_typeof('"true"') AS string;
SELECT jsonb_typeof('"1.0"') AS string;
-- jsonb_build_array, jsonb_build_object, jsonb_object_agg
SELECT jsonb_build_array('a',1,'b',1.2,'c',true,'d',null,'e',json '{"x": 3, "y": [1,2,3]}');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
-- jsonb_build_array, jsonb_build_object, jsonb_object_agg
^
-stdin-::1:1: Fatal: ERROR: could not determine data type for argument 1
-- jsonb_build_array, jsonb_build_object, jsonb_object_agg
^
SELECT jsonb_build_array('a', NULL); -- ok
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_array('a', NULL); -- ok
^
-stdin-::1:1: Fatal: ERROR: could not determine data type for argument 1
SELECT jsonb_build_array('a', NULL); -- ok
^
SELECT jsonb_build_array(VARIADIC NULL::text[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_array(VARIADIC NULL::text[]); -- ok
^
SELECT jsonb_build_array(VARIADIC '{}'::text[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_array(VARIADIC '{}'::text[]); -- ok
^
SELECT jsonb_build_array(VARIADIC '{a,b,c}'::text[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_array(VARIADIC '{a,b,c}'::text[]); -- ok
^
SELECT jsonb_build_array(VARIADIC ARRAY['a', NULL]::text[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_array(VARIADIC ARRAY['a', NULL]::text[]); -- ok
^
SELECT jsonb_build_array(VARIADIC '{1,2,3,4}'::text[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_array(VARIADIC '{1,2,3,4}'::text[]); -- ok
^
SELECT jsonb_build_array(VARIADIC '{1,2,3,4}'::int[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_array(VARIADIC '{1,2,3,4}'::int[]); -- ok
^
SELECT jsonb_build_array(VARIADIC '{{1,4},{2,5},{3,6}}'::int[][]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_array(VARIADIC '{{1,4},{2,5},{3,6}}'::int[][]); -- ok
^
SELECT jsonb_build_object('a',1,'b',1.2,'c',true,'d',null,'e',json '{"x": 3, "y": [1,2,3]}');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_object('a',1,'b',1.2,'c',true,'d',null,'e',json '{"x": 3, "y": [1,2,3]}');
^
-stdin-::1:1: Fatal: ERROR: could not determine data type for argument 1
SELECT jsonb_build_object('a',1,'b',1.2,'c',true,'d',null,'e',json '{"x": 3, "y": [1,2,3]}');
^
SELECT jsonb_build_object(
'a', jsonb_build_object('b',false,'c',99),
'd', jsonb_build_object('e',array[9,8,7]::int[],
'f', (select row_to_json(r) from ( select relkind, oid::regclass as name from pg_class where relname = 'pg_class') r)));
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_object(
^
-stdin-::1:1: Fatal: ERROR: could not determine data type for argument 1
SELECT jsonb_build_object(
^
SELECT jsonb_build_object('{a,b,c}'::text[]); -- error
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_object('{a,b,c}'::text[]); -- error
^
-stdin-::1:1: Fatal: ERROR: argument list must have even number of elements
HINT: The arguments of jsonb_build_object() must consist of alternating keys and values.
SELECT jsonb_build_object('{a,b,c}'::text[]); -- error
^
SELECT jsonb_build_object('{a,b,c}'::text[], '{d,e,f}'::text[]); -- error, key cannot be array
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_object('{a,b,c}'::text[], '{d,e,f}'::text[]); -- error, key cannot be array
^
-stdin-::1:1: Fatal: ERROR: key value must be scalar, not array, composite, or json
SELECT jsonb_build_object('{a,b,c}'::text[], '{d,e,f}'::text[]); -- error, key cannot be array
^
SELECT jsonb_build_object('a', 'b', 'c'); -- error
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_object('a', 'b', 'c'); -- error
^
-stdin-::1:1: Fatal: ERROR: could not determine data type for argument 1
SELECT jsonb_build_object('a', 'b', 'c'); -- error
^
SELECT jsonb_build_object(NULL, 'a'); -- error, key cannot be NULL
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_object(NULL, 'a'); -- error, key cannot be NULL
^
-stdin-::1:1: Fatal: ERROR: could not determine data type for argument 1
SELECT jsonb_build_object(NULL, 'a'); -- error, key cannot be NULL
^
SELECT jsonb_build_object('a', NULL); -- ok
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_object('a', NULL); -- ok
^
-stdin-::1:1: Fatal: ERROR: could not determine data type for argument 1
SELECT jsonb_build_object('a', NULL); -- ok
^
SELECT jsonb_build_object(VARIADIC NULL::text[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_object(VARIADIC NULL::text[]); -- ok
^
SELECT jsonb_build_object(VARIADIC '{}'::text[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_object(VARIADIC '{}'::text[]); -- ok
^
SELECT jsonb_build_object(VARIADIC '{a,b,c}'::text[]); -- error
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_object(VARIADIC '{a,b,c}'::text[]); -- error
^
SELECT jsonb_build_object(VARIADIC ARRAY['a', NULL]::text[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_object(VARIADIC ARRAY['a', NULL]::text[]); -- ok
^
SELECT jsonb_build_object(VARIADIC ARRAY[NULL, 'a']::text[]); -- error, key cannot be NULL
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_object(VARIADIC ARRAY[NULL, 'a']::text[]); -- error, key cannot be NULL
^
SELECT jsonb_build_object(VARIADIC '{1,2,3,4}'::text[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_object(VARIADIC '{1,2,3,4}'::text[]); -- ok
^
SELECT jsonb_build_object(VARIADIC '{1,2,3,4}'::int[]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_object(VARIADIC '{1,2,3,4}'::int[]); -- ok
^
SELECT jsonb_build_object(VARIADIC '{{1,4},{2,5},{3,6}}'::int[][]); -- ok
-stdin-:: Error: Parse Sql
-stdin-::1:8: Error: FuncCall: unsupported func_variadic
SELECT jsonb_build_object(VARIADIC '{{1,4},{2,5},{3,6}}'::int[][]); -- ok
^
-- empty objects/arrays
SELECT jsonb_build_array();
SELECT jsonb_build_object();
-- make sure keys are quoted
SELECT jsonb_build_object(1,2);
-- keys must be scalar and not null
SELECT jsonb_build_object(null,2);
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
-- keys must be scalar and not null
^
-stdin-::1:1: Fatal: ERROR: could not determine data type for argument 1
-- keys must be scalar and not null
^
SELECT jsonb_build_object(r,2) FROM (SELECT 1 AS a, 2 AS b) r;
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_object(r,2) FROM (SELECT 1 AS a, 2 AS b) r;
^
-stdin-::1:1: Fatal: ERROR: key value must be scalar, not array, composite, or json
SELECT jsonb_build_object(r,2) FROM (SELECT 1 AS a, 2 AS b) r;
^
SELECT jsonb_build_object(json '{"a":1,"b":2}', 3);
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_object(json '{"a":1,"b":2}', 3);
^
-stdin-::1:1: Fatal: ERROR: key value must be scalar, not array, composite, or json
SELECT jsonb_build_object(json '{"a":1,"b":2}', 3);
^
SELECT jsonb_build_object('{1,2,3}'::int[], 3);
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_build_object('{1,2,3}'::int[], 3);
^
-stdin-::1:1: Fatal: ERROR: key value must be scalar, not array, composite, or json
SELECT jsonb_build_object('{1,2,3}'::int[], 3);
^
-- handling of NULL values
SELECT jsonb_object_agg(1, NULL::jsonb);
SELECT jsonb_object_agg(NULL, '{"a":1}');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
SELECT jsonb_object_agg(NULL, '{"a":1}');
^
-stdin-::1:1: Fatal: ERROR: field name must not be null
SELECT jsonb_object_agg(NULL, '{"a":1}');
^
CREATE TEMP TABLE foo (serial_num int, name text, type text);
INSERT INTO foo VALUES (847001,'t15','GE1043');
INSERT INTO foo VALUES (847002,'t16','GE1043');
INSERT INTO foo VALUES (847003,'sub-alpha','GESS90');
SELECT jsonb_build_object('turbines',jsonb_object_agg(serial_num,jsonb_build_object('name',name,'type',type)))
FROM foo;
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: YtMapReduce!
SELECT jsonb_build_object('turbines',jsonb_object_agg(serial_num,jsonb_build_object('name',name,'type',type)))
^
-stdin-::1:1: Fatal: ERROR: could not determine data type for argument 1
SELECT jsonb_build_object('turbines',jsonb_object_agg(serial_num,jsonb_build_object('name',name,'type',type)))
^
SELECT jsonb_object_agg(name, type) FROM foo;
INSERT INTO foo VALUES (999999, NULL, 'bar');
SELECT jsonb_object_agg(name, type) FROM foo;
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: YtMapReduce!
SELECT jsonb_object_agg(name, type) FROM foo;
^
-stdin-::1:1: Fatal: ERROR: field name must not be null
SELECT jsonb_object_agg(name, type) FROM foo;
^
-- jsonb_object
-- empty object, one dimension
SELECT jsonb_object('{}');
-- empty object, two dimensions
SELECT jsonb_object('{}', '{}');
-- one dimension
SELECT jsonb_object('{a,1,b,2,3,NULL,"d e f","a b c"}');
-- same but with two dimensions
SELECT jsonb_object('{{a,1},{b,2},{3,NULL},{"d e f","a b c"}}');
-- odd number error
SELECT jsonb_object('{a,b,c}');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
-- odd number error
^
-stdin-::1:1: Fatal: ERROR: array must have even number of elements
-- odd number error
^
-- one column error
SELECT jsonb_object('{{a},{b}}');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
-- one column error
^
-stdin-::1:1: Fatal: ERROR: array must have two columns
-- one column error
^
-- too many columns error
SELECT jsonb_object('{{a,b,c},{b,c,d}}');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
-- too many columns error
^
-stdin-::1:1: Fatal: ERROR: array must have two columns
-- too many columns error
^
-- too many dimensions error
SELECT jsonb_object('{{{a,b},{c,d}},{{b,c},{d,e}}}');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
-- too many dimensions error
^
-stdin-::1:1: Fatal: ERROR: wrong number of array subscripts
-- too many dimensions error
^
--two argument form of jsonb_object
select jsonb_object('{a,b,c,"d e f"}','{1,2,3,"a b c"}');
-- too many dimensions
SELECT jsonb_object('{{a,1},{b,2},{3,NULL},{"d e f","a b c"}}', '{{a,1},{b,2},{3,NULL},{"d e f","a b c"}}');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
-- too many dimensions
^
-stdin-::1:1: Fatal: ERROR: wrong number of array subscripts
-- too many dimensions
^
-- mismatched dimensions
select jsonb_object('{a,b,c,"d e f",g}','{1,2,3,"a b c"}');
-stdin-:: Fatal: Execution
-stdin-::1:1: Fatal: Execution of node: Result
-- mismatched dimensions
^
-stdin-::1:1: Fatal: ERROR: mismatched array dimensions
-- mismatched dimensions
^
select jsonb_object('{a,b,c,"d e f"}','{1,2,3,"a b c",g}');
-stdin-:: Fatal: Execution
-stdin-: