2 -- Should fail (JSON_TABLE can be used only in FROM clause)
3 SELECT JSON_TABLE('[]', '$');
4 ERROR: syntax error at or near "("
5 LINE 1: SELECT JSON_TABLE('[]', '$');
7 -- Only allow EMPTY and ERROR for ON ERROR
8 SELECT * FROM JSON_TABLE('[]', 'strict $.a' COLUMNS (js2 int PATH '$') DEFAULT 1 ON ERROR);
9 ERROR: invalid ON ERROR behavior
10 LINE 1: ...BLE('[]', 'strict $.a' COLUMNS (js2 int PATH '$') DEFAULT 1 ...
12 DETAIL: Only EMPTY [ ARRAY ] or ERROR is allowed in the top-level ON ERROR clause.
13 SELECT * FROM JSON_TABLE('[]', 'strict $.a' COLUMNS (js2 int PATH '$') NULL ON ERROR);
14 ERROR: invalid ON ERROR behavior
15 LINE 1: ...BLE('[]', 'strict $.a' COLUMNS (js2 int PATH '$') NULL ON ER...
17 DETAIL: Only EMPTY [ ARRAY ] or ERROR is allowed in the top-level ON ERROR clause.
18 SELECT * FROM JSON_TABLE('[]', 'strict $.a' COLUMNS (js2 int PATH '$') EMPTY ON ERROR);
23 SELECT * FROM JSON_TABLE('[]', 'strict $.a' COLUMNS (js2 int PATH '$') ERROR ON ERROR);
24 ERROR: jsonpath member accessor can only be applied to an object
25 -- Column and path names must be distinct
26 SELECT * FROM JSON_TABLE(jsonb'"1.23"', '$.a' as js2 COLUMNS (js2 int path '$'));
27 ERROR: duplicate JSON_TABLE column or path name: js2
28 LINE 1: ...M JSON_TABLE(jsonb'"1.23"', '$.a' as js2 COLUMNS (js2 int pa...
30 -- Should fail (no columns)
31 SELECT * FROM JSON_TABLE(NULL, '$' COLUMNS ());
32 ERROR: syntax error at or near ")"
33 LINE 1: SELECT * FROM JSON_TABLE(NULL, '$' COLUMNS ());
35 SELECT * FROM JSON_TABLE (NULL::jsonb, '$' COLUMNS (v1 timestamp)) AS f (v1, v2);
36 ERROR: JSON_TABLE function has 1 columns available but 2 columns specified
37 --duplicated column name
38 SELECT * FROM JSON_TABLE(jsonb'"1.23"', '$.a' COLUMNS (js2 int path '$', js2 int path '$'));
39 ERROR: duplicate JSON_TABLE column or path name: js2
40 LINE 1: ...E(jsonb'"1.23"', '$.a' COLUMNS (js2 int path '$', js2 int pa...
42 --return composite data type.
43 create type comp as (a int, b int);
44 SELECT * FROM JSON_TABLE(jsonb '{"rec": "(1,2)"}', '$' COLUMNS (id FOR ORDINALITY, comp comp path '$.rec' omit quotes)) jt;
51 -- NULL => empty table
52 SELECT * FROM JSON_TABLE(NULL::jsonb, '$' COLUMNS (foo int)) bar;
57 SELECT * FROM JSON_TABLE(jsonb'"1.23"', 'strict $.a' COLUMNS (js2 int PATH '$'));
63 SELECT * FROM JSON_TABLE(jsonb '123', '$'
64 COLUMNS (item int PATH '$', foo int)) bar;
70 -- JSON_TABLE: basic functionality
71 CREATE DOMAIN jsonb_test_domain AS text CHECK (value <> 'foo');
72 CREATE TEMP TABLE json_table_test (js) AS
77 ('[1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""]')
79 -- Regular "unformatted" columns
81 FROM json_table_test vals
84 vals.js::jsonb, 'lax $[*]'
89 "char(4)" char(4) PATH '$',
91 "numeric" numeric PATH '$',
92 "domain" jsonb_test_domain PATH '$',
98 js | id | int | text | char(4) | bool | numeric | domain | js | jb
99 ---------------------------------------------------------------------------------------+----+-----+---------+---------+------+---------+---------+--------------+--------------
100 1 | 1 | 1 | 1 | 1 | t | 1 | 1 | 1 | 1
102 {} | 1 | | | | | | | {} | {}
103 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 1 | 1 | 1 | 1 | t | 1 | 1 | 1 | 1
104 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 2 | | 1.23 | 1.23 | | 1.23 | 1.23 | 1.23 | 1.23
105 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 3 | 2 | 2 | 2 | | 2 | 2 | "2" | "2"
106 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 4 | | aaaaaaa | | | | aaaaaaa | "aaaaaaa" | "aaaaaaa"
107 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 5 | | foo | foo | | | | "foo" | "foo"
108 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 6 | | | | | | | null | null
109 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 7 | | f | f | f | | false | false | false
110 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 8 | | t | t | t | | true | true | true
111 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 9 | | | | | | | {"aaa": 123} | {"aaa": 123}
112 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 10 | | [1,2] | | | | [1,2] | "[1,2]" | "[1,2]"
113 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 11 | | "str" | | | | "str" | "\"str\"" | "\"str\""
116 -- "formatted" columns
118 FROM json_table_test vals
121 vals.js::jsonb, 'lax $[*]'
124 jst text FORMAT JSON PATH '$',
125 jsc char(4) FORMAT JSON PATH '$',
126 jsv varchar(4) FORMAT JSON PATH '$',
127 jsb jsonb FORMAT JSON PATH '$',
128 jsbq jsonb FORMAT JSON PATH '$' OMIT QUOTES
132 js | id | jst | jsc | jsv | jsb | jsbq
133 ---------------------------------------------------------------------------------------+----+--------------+------+------+--------------+--------------
134 1 | 1 | 1 | 1 | 1 | 1 | 1
136 {} | 1 | {} | {} | {} | {} | {}
137 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 1 | 1 | 1 | 1 | 1 | 1
138 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 2 | 1.23 | 1.23 | 1.23 | 1.23 | 1.23
139 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 3 | "2" | "2" | "2" | "2" | 2
140 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 4 | "aaaaaaa" | | | "aaaaaaa" |
141 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 5 | "foo" | | | "foo" |
142 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 6 | null | null | null | null | null
143 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 7 | false | | | false | false
144 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 8 | true | true | true | true | true
145 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 9 | {"aaa": 123} | | | {"aaa": 123} | {"aaa": 123}
146 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 10 | "[1,2]" | | | "[1,2]" | [1, 2]
147 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 11 | "\"str\"" | | | "\"str\"" | "str"
152 FROM json_table_test vals
155 vals.js::jsonb, 'lax $[*]'
158 exists1 bool EXISTS PATH '$.aaa',
159 exists2 int EXISTS PATH '$.aaa',
160 exists3 int EXISTS PATH 'strict $.aaa' UNKNOWN ON ERROR,
161 exists4 text EXISTS PATH 'strict $.aaa' FALSE ON ERROR
165 js | id | exists1 | exists2 | exists3 | exists4
166 ---------------------------------------------------------------------------------------+----+---------+---------+---------+---------
167 1 | 1 | f | 0 | | false
169 {} | 1 | f | 0 | | false
170 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 1 | f | 0 | | false
171 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 2 | f | 0 | | false
172 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 3 | f | 0 | | false
173 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 4 | f | 0 | | false
174 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 5 | f | 0 | | false
175 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 6 | f | 0 | | false
176 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 7 | f | 0 | | false
177 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 8 | f | 0 | | false
178 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 9 | t | 1 | 1 | true
179 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 10 | f | 0 | | false
180 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 11 | f | 0 | | false
183 -- Other miscellaneous checks
185 FROM json_table_test vals
188 vals.js::jsonb, 'lax $[*]'
191 aaa int, -- "aaa" has implicit path '$."aaa"'
192 aaa1 int PATH '$.aaa',
194 jsb2w jsonb PATH '$' WITH WRAPPER,
195 jsb2q jsonb PATH '$' OMIT QUOTES,
202 js | id | aaa | aaa1 | js2 | jsb2w | jsb2q | ia | ta | jba
203 ---------------------------------------------------------------------------------------+----+-----+------+--------------+----------------+--------------+----+----+-----
204 1 | 1 | | | 1 | [1] | 1 | | |
206 {} | 1 | | | {} | [{}] | {} | | |
207 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 1 | | | 1 | [1] | 1 | | |
208 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 2 | | | 1.23 | [1.23] | 1.23 | | |
209 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 3 | | | "2" | ["2"] | 2 | | |
210 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 4 | | | "aaaaaaa" | ["aaaaaaa"] | | | |
211 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 5 | | | "foo" | ["foo"] | | | |
212 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 6 | | | null | [null] | null | | |
213 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 7 | | | false | [false] | false | | |
214 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 8 | | | true | [true] | true | | |
215 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 9 | 123 | 123 | {"aaa": 123} | [{"aaa": 123}] | {"aaa": 123} | | |
216 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 10 | | | "[1,2]" | ["[1,2]"] | [1, 2] | | |
217 [1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""] | 11 | | | "\"str\"" | ["\"str\""] | "str" | | |
220 -- Test using casts in DEFAULT .. ON ERROR expression
221 SELECT * FROM JSON_TABLE(jsonb '{"d1": "H"}', '$'
222 COLUMNS (js1 jsonb_test_domain PATH '$.a2' DEFAULT '"foo1"'::jsonb::text ON EMPTY));
228 SELECT * FROM JSON_TABLE(jsonb '{"d1": "H"}', '$'
229 COLUMNS (js1 jsonb_test_domain PATH '$.a2' DEFAULT 'foo'::jsonb_test_domain ON EMPTY));
230 ERROR: could not coerce ON EMPTY expression (DEFAULT) to the RETURNING type
231 DETAIL: value for domain jsonb_test_domain violates check constraint "jsonb_test_domain_check"
232 SELECT * FROM JSON_TABLE(jsonb '{"d1": "H"}', '$'
233 COLUMNS (js1 jsonb_test_domain PATH '$.a2' DEFAULT 'foo1'::jsonb_test_domain ON EMPTY));
239 SELECT * FROM JSON_TABLE(jsonb '{"d1": "foo"}', '$'
240 COLUMNS (js1 jsonb_test_domain PATH '$.d1' DEFAULT 'foo2'::jsonb_test_domain ON ERROR));
246 SELECT * FROM JSON_TABLE(jsonb '{"d1": "foo"}', '$'
247 COLUMNS (js1 oid[] PATH '$.d2' DEFAULT '{1}'::int[]::oid[] ON EMPTY));
253 -- JSON_TABLE: Test backward parsing
254 CREATE VIEW jsonb_table_view2 AS
257 jsonb 'null', 'lax $[*]' PASSING 1 + 2 AS a, json '"foo"' AS "b c"
260 "text" text PATH '$',
261 "char(4)" char(4) PATH '$',
262 "bool" bool PATH '$',
263 "numeric" numeric PATH '$',
264 "domain" jsonb_test_domain PATH '$'));
265 CREATE VIEW jsonb_table_view3 AS
268 jsonb 'null', 'lax $[*]' PASSING 1 + 2 AS a, json '"foo"' AS "b c"
272 jst text FORMAT JSON PATH '$',
273 jsc char(4) FORMAT JSON PATH '$',
274 jsv varchar(4) FORMAT JSON PATH '$'));
275 CREATE VIEW jsonb_table_view4 AS
278 jsonb 'null', 'lax $[*]' PASSING 1 + 2 AS a, json '"foo"' AS "b c"
280 jsb jsonb FORMAT JSON PATH '$',
281 jsbq jsonb FORMAT JSON PATH '$' OMIT QUOTES,
282 aaa int, -- implicit path '$."aaa"',
283 aaa1 int PATH '$.aaa'));
284 CREATE VIEW jsonb_table_view5 AS
287 jsonb 'null', 'lax $[*]' PASSING 1 + 2 AS a, json '"foo"' AS "b c"
289 exists1 bool EXISTS PATH '$.aaa',
290 exists2 int EXISTS PATH '$.aaa' TRUE ON ERROR,
291 exists3 text EXISTS PATH 'strict $.aaa' UNKNOWN ON ERROR));
292 CREATE VIEW jsonb_table_view6 AS
295 jsonb 'null', 'lax $[*]' PASSING 1 + 2 AS a, json '"foo"' AS "b c"
298 jsb2w jsonb PATH '$' WITH WRAPPER,
299 jsb2q jsonb PATH '$' OMIT QUOTES,
302 jba jsonb[] PATH '$'));
303 \sv jsonb_table_view2
304 CREATE OR REPLACE VIEW public.jsonb_table_view2 AS
312 'null'::jsonb, '$[*]' AS json_table_path_0
315 '"foo"'::json AS "b c"
317 "int" integer PATH '$',
319 "char(4)" character(4) PATH '$',
320 bool boolean PATH '$',
321 "numeric" numeric PATH '$',
322 domain jsonb_test_domain PATH '$'
325 \sv jsonb_table_view3
326 CREATE OR REPLACE VIEW public.jsonb_table_view3 AS
333 'null'::jsonb, '$[*]' AS json_table_path_0
336 '"foo"'::json AS "b c"
338 js json PATH '$' WITHOUT WRAPPER KEEP QUOTES,
339 jb jsonb PATH '$' WITHOUT WRAPPER KEEP QUOTES,
340 jst text FORMAT JSON PATH '$' WITHOUT WRAPPER KEEP QUOTES,
341 jsc character(4) FORMAT JSON PATH '$' WITHOUT WRAPPER KEEP QUOTES,
342 jsv character varying(4) FORMAT JSON PATH '$' WITHOUT WRAPPER KEEP QUOTES
345 \sv jsonb_table_view4
346 CREATE OR REPLACE VIEW public.jsonb_table_view4 AS
352 'null'::jsonb, '$[*]' AS json_table_path_0
355 '"foo"'::json AS "b c"
357 jsb jsonb PATH '$' WITHOUT WRAPPER KEEP QUOTES,
358 jsbq jsonb PATH '$' WITHOUT WRAPPER OMIT QUOTES,
359 aaa integer PATH '$."aaa"',
360 aaa1 integer PATH '$."aaa"'
363 \sv jsonb_table_view5
364 CREATE OR REPLACE VIEW public.jsonb_table_view5 AS
369 'null'::jsonb, '$[*]' AS json_table_path_0
372 '"foo"'::json AS "b c"
374 exists1 boolean EXISTS PATH '$."aaa"',
375 exists2 integer EXISTS PATH '$."aaa"' TRUE ON ERROR,
376 exists3 text EXISTS PATH 'strict $."aaa"' UNKNOWN ON ERROR
379 \sv jsonb_table_view6
380 CREATE OR REPLACE VIEW public.jsonb_table_view6 AS
388 'null'::jsonb, '$[*]' AS json_table_path_0
391 '"foo"'::json AS "b c"
393 js2 json PATH '$' WITHOUT WRAPPER KEEP QUOTES,
394 jsb2w jsonb PATH '$' WITH UNCONDITIONAL WRAPPER KEEP QUOTES,
395 jsb2q jsonb PATH '$' WITHOUT WRAPPER OMIT QUOTES,
396 ia integer[] PATH '$' WITHOUT WRAPPER KEEP QUOTES,
397 ta text[] PATH '$' WITHOUT WRAPPER KEEP QUOTES,
398 jba jsonb[] PATH '$' WITHOUT WRAPPER KEEP QUOTES
401 EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM jsonb_table_view2;
403 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
404 Table Function Scan on "json_table"
405 Output: "json_table"."int", "json_table".text, "json_table"."char(4)", "json_table".bool, "json_table"."numeric", "json_table".domain
406 Table Function Call: JSON_TABLE('null'::jsonb, '$[*]' AS json_table_path_0 PASSING 3 AS a, '"foo"'::jsonb AS "b c" COLUMNS ("int" integer PATH '$', text text PATH '$', "char(4)" character(4) PATH '$', bool boolean PATH '$', "numeric" numeric PATH '$', domain jsonb_test_domain PATH '$'))
409 EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM jsonb_table_view3;
411 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
412 Table Function Scan on "json_table"
413 Output: "json_table".js, "json_table".jb, "json_table".jst, "json_table".jsc, "json_table".jsv
414 Table Function Call: JSON_TABLE('null'::jsonb, '$[*]' AS json_table_path_0 PASSING 3 AS a, '"foo"'::jsonb AS "b c" COLUMNS (js json PATH '$' WITHOUT WRAPPER KEEP QUOTES, jb jsonb PATH '$' WITHOUT WRAPPER KEEP QUOTES, jst text FORMAT JSON PATH '$' WITHOUT WRAPPER KEEP QUOTES, jsc character(4) FORMAT JSON PATH '$' WITHOUT WRAPPER KEEP QUOTES, jsv character varying(4) FORMAT JSON PATH '$' WITHOUT WRAPPER KEEP QUOTES))
417 EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM jsonb_table_view4;
419 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
420 Table Function Scan on "json_table"
421 Output: "json_table".jsb, "json_table".jsbq, "json_table".aaa, "json_table".aaa1
422 Table Function Call: JSON_TABLE('null'::jsonb, '$[*]' AS json_table_path_0 PASSING 3 AS a, '"foo"'::jsonb AS "b c" COLUMNS (jsb jsonb PATH '$' WITHOUT WRAPPER KEEP QUOTES, jsbq jsonb PATH '$' WITHOUT WRAPPER OMIT QUOTES, aaa integer PATH '$."aaa"', aaa1 integer PATH '$."aaa"'))
425 EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM jsonb_table_view5;
427 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
428 Table Function Scan on "json_table"
429 Output: "json_table".exists1, "json_table".exists2, "json_table".exists3
430 Table Function Call: JSON_TABLE('null'::jsonb, '$[*]' AS json_table_path_0 PASSING 3 AS a, '"foo"'::jsonb AS "b c" COLUMNS (exists1 boolean EXISTS PATH '$."aaa"', exists2 integer EXISTS PATH '$."aaa"' TRUE ON ERROR, exists3 text EXISTS PATH 'strict $."aaa"' UNKNOWN ON ERROR))
433 EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM jsonb_table_view6;
435 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
436 Table Function Scan on "json_table"
437 Output: "json_table".js2, "json_table".jsb2w, "json_table".jsb2q, "json_table".ia, "json_table".ta, "json_table".jba
438 Table Function Call: JSON_TABLE('null'::jsonb, '$[*]' AS json_table_path_0 PASSING 3 AS a, '"foo"'::jsonb AS "b c" COLUMNS (js2 json PATH '$' WITHOUT WRAPPER KEEP QUOTES, jsb2w jsonb PATH '$' WITH UNCONDITIONAL WRAPPER KEEP QUOTES, jsb2q jsonb PATH '$' WITHOUT WRAPPER OMIT QUOTES, ia integer[] PATH '$' WITHOUT WRAPPER KEEP QUOTES, ta text[] PATH '$' WITHOUT WRAPPER KEEP QUOTES, jba jsonb[] PATH '$' WITHOUT WRAPPER KEEP QUOTES))
441 -- JSON_TABLE() with alias
442 EXPLAIN (COSTS OFF, VERBOSE)
445 jsonb 'null', 'lax $[*]' PASSING 1 + 2 AS a, json '"foo"' AS "b c"
452 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
453 Table Function Scan on "json_table" json_table_func
454 Output: id, "int", text
455 Table Function Call: JSON_TABLE('null'::jsonb, '$[*]' AS json_table_path_0 PASSING 3 AS a, '"foo"'::jsonb AS "b c" COLUMNS (id FOR ORDINALITY, "int" integer PATH '$', text text PATH '$'))
458 EXPLAIN (COSTS OFF, FORMAT JSON, VERBOSE)
461 jsonb 'null', 'lax $[*]' PASSING 1 + 2 AS a, json '"foo"' AS "b c"
468 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
472 "Node Type": "Table Function Scan", +
473 "Parallel Aware": false, +
474 "Async Capable": false, +
475 "Table Function Name": "json_table", +
476 "Alias": "json_table_func", +
478 "Output": ["id", "\"int\"", "text"], +
479 "Table Function Call": "JSON_TABLE('null'::jsonb, '$[*]' AS json_table_path_0 PASSING 3 AS a, '\"foo\"'::jsonb AS \"b c\" COLUMNS (id FOR ORDINALITY, \"int\" integer PATH '$', text text PATH '$'))"+
485 DROP VIEW jsonb_table_view2;
486 DROP VIEW jsonb_table_view3;
487 DROP VIEW jsonb_table_view4;
488 DROP VIEW jsonb_table_view5;
489 DROP VIEW jsonb_table_view6;
490 DROP DOMAIN jsonb_test_domain;
491 -- JSON_TABLE: only one FOR ORDINALITY columns allowed
492 SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (id FOR ORDINALITY, id2 FOR ORDINALITY, a int PATH '$.a' ERROR ON EMPTY)) jt;
493 ERROR: only one FOR ORDINALITY column is allowed
494 LINE 1: ..._TABLE(jsonb '1', '$' COLUMNS (id FOR ORDINALITY, id2 FOR OR...
496 SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (id FOR ORDINALITY, a int PATH '$' ERROR ON EMPTY)) jt;
502 -- JSON_TABLE: ON EMPTY/ON ERROR behavior
505 (VALUES ('1'), ('"err"')) vals(js),
506 JSON_TABLE(vals.js::jsonb, '$' COLUMNS (a int PATH '$')) jt;
515 (VALUES ('1'), ('"err"')) vals(js)
517 JSON_TABLE(vals.js::jsonb, '$' COLUMNS (a int PATH '$' ERROR ON ERROR)) jt
519 ERROR: invalid input syntax for type integer: "err"
520 -- TABLE-level ERROR ON ERROR is not propagated to columns
523 (VALUES ('1'), ('"err"')) vals(js)
525 JSON_TABLE(vals.js::jsonb, '$' COLUMNS (a int PATH '$' ERROR ON ERROR)) jt
527 ERROR: invalid input syntax for type integer: "err"
528 SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int PATH '$.a' ERROR ON EMPTY)) jt;
529 ERROR: no SQL/JSON item found for specified path of column "a"
530 SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int PATH 'strict $.a' ERROR ON ERROR) ERROR ON ERROR) jt;
531 ERROR: jsonpath member accessor can only be applied to an object
532 SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int PATH 'lax $.a' ERROR ON EMPTY) ERROR ON ERROR) jt;
533 ERROR: no SQL/JSON item found for specified path of column "a"
534 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a int PATH '$' DEFAULT 1 ON EMPTY DEFAULT 2 ON ERROR)) jt;
540 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a int PATH 'strict $.a' DEFAULT 1 ON EMPTY DEFAULT 2 ON ERROR)) jt;
546 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a int PATH 'lax $.a' DEFAULT 1 ON EMPTY DEFAULT 2 ON ERROR)) jt;
552 -- JSON_TABLE: EXISTS PATH types
553 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a int4 EXISTS PATH '$.a' ERROR ON ERROR)); -- ok; can cast to int4
559 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a int4 EXISTS PATH '$' ERROR ON ERROR)); -- ok; can cast to int4
565 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a int2 EXISTS PATH '$.a'));
566 ERROR: could not coerce ON ERROR expression (FALSE) to the RETURNING type
567 DETAIL: invalid input syntax for type smallint: "false"
568 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a int8 EXISTS PATH '$.a'));
569 ERROR: could not coerce ON ERROR expression (FALSE) to the RETURNING type
570 DETAIL: invalid input syntax for type bigint: "false"
571 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a float4 EXISTS PATH '$.a'));
572 ERROR: could not coerce ON ERROR expression (FALSE) to the RETURNING type
573 DETAIL: invalid input syntax for type real: "false"
574 -- Default FALSE (ON ERROR) doesn't fit char(3)
575 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a char(3) EXISTS PATH '$.a'));
576 ERROR: could not coerce ON ERROR expression (FALSE) to the RETURNING type
577 DETAIL: value too long for type character(3)
578 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a char(3) EXISTS PATH '$.a' ERROR ON ERROR));
579 ERROR: value too long for type character(3)
580 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a char(5) EXISTS PATH '$.a' ERROR ON ERROR));
586 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a json EXISTS PATH '$.a'));
592 SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a jsonb EXISTS PATH '$.a'));
598 -- EXISTS PATH domain over int
599 CREATE DOMAIN dint4 AS int;
600 CREATE DOMAIN dint4_0 AS int CHECK (VALUE <> 0 );
601 SELECT a, a::bool FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a dint4 EXISTS PATH '$.a' ));
607 SELECT a, a::bool FROM JSON_TABLE(jsonb '{"a":1}', '$' COLUMNS (a dint4_0 EXISTS PATH '$.b'));
608 ERROR: could not coerce ON ERROR expression (FALSE) to the RETURNING type
609 DETAIL: value for domain dint4_0 violates check constraint "dint4_0_check"
610 SELECT a, a::bool FROM JSON_TABLE(jsonb '{"a":1}', '$' COLUMNS (a dint4_0 EXISTS PATH '$.b' ERROR ON ERROR));
611 ERROR: value for domain dint4_0 violates check constraint "dint4_0_check"
612 SELECT a, a::bool FROM JSON_TABLE(jsonb '{"a":1}', '$' COLUMNS (a dint4_0 EXISTS PATH '$.b' FALSE ON ERROR));
613 ERROR: could not coerce ON ERROR expression (FALSE) to the RETURNING type
614 DETAIL: value for domain dint4_0 violates check constraint "dint4_0_check"
615 SELECT a, a::bool FROM JSON_TABLE(jsonb '{"a":1}', '$' COLUMNS (a dint4_0 EXISTS PATH '$.b' TRUE ON ERROR));
621 DROP DOMAIN dint4, dint4_0;
622 -- JSON_TABLE: WRAPPER/QUOTES clauses on scalar columns
623 SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text PATH '$' KEEP QUOTES ON SCALAR STRING));
629 SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text PATH '$' OMIT QUOTES ON SCALAR STRING));
635 SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text FORMAT JSON PATH '$' KEEP QUOTES));
641 SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text FORMAT JSON PATH '$' OMIT QUOTES));
647 SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text FORMAT JSON PATH '$' WITHOUT WRAPPER KEEP QUOTES));
653 SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text PATH '$' WITHOUT WRAPPER OMIT QUOTES));
659 SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text FORMAT JSON PATH '$' WITH WRAPPER));
665 -- Error: OMIT QUOTES should not be specified when WITH WRAPPER is present
666 SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text PATH '$' WITH WRAPPER OMIT QUOTES));
667 ERROR: SQL/JSON QUOTES behavior must not be specified when WITH WRAPPER is used
668 LINE 1: ...T * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text ...
670 -- But KEEP QUOTES (the default) is fine
671 SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text FORMAT JSON PATH '$' WITH WRAPPER KEEP QUOTES));
683 COLUMNS (y text FORMAT JSON PATH '$')
691 -- PASSING arguments are also passed to column paths
696 PASSING 10 AS x, 3 AS y
697 COLUMNS (a text FORMAT JSON PATH '$ ? (@ < $y)')
706 -- Should fail (not supported)
707 SELECT * FROM JSON_TABLE(jsonb '{"a": 123}', '$' || '.' || 'a' COLUMNS (foo int));
708 ERROR: only string constants are supported in JSON_TABLE path specification
709 LINE 1: SELECT * FROM JSON_TABLE(jsonb '{"a": 123}', '$' || '.' || '...
711 -- JsonPathQuery() error message mentioning column name
712 SELECT * FROM JSON_TABLE('{"a": [{"b": "1"}, {"b": "2"}]}', '$' COLUMNS (b json path '$.a[*].b' ERROR ON ERROR));
713 ERROR: JSON path expression for column "b" should return single item without wrapper
714 HINT: Use the WITH WRAPPER clause to wrap SQL/JSON items into an array.
715 -- JSON_TABLE: nested paths
716 -- Duplicate path names
717 SELECT * FROM JSON_TABLE(
727 ERROR: duplicate JSON_TABLE column or path name: a
728 LINE 5: NESTED PATH '$' AS a
730 SELECT * FROM JSON_TABLE(
734 NESTED PATH '$' AS n_a
745 SELECT * FROM JSON_TABLE(
755 ERROR: duplicate JSON_TABLE column or path name: b
756 LINE 5: NESTED PATH '$' AS b
758 SELECT * FROM JSON_TABLE(
774 ERROR: duplicate JSON_TABLE column or path name: a
775 LINE 10: NESTED PATH '$' AS a
777 -- JSON_TABLE: plan execution
778 CREATE TEMP TABLE jsonb_table_test (js jsonb);
779 INSERT INTO jsonb_table_test
782 {"a": 1, "b": [], "c": []},
783 {"a": 2, "b": [1, 2, 3], "c": [10, null, 20]},
784 {"a": 3, "b": [1, 2], "c": []},
785 {"x": "4", "b": [1, 2], "c": 123}
791 jsonb_table_test jtt,
793 jtt.js,'strict $[*]' as p
796 a int path 'lax $.a' default -1 on empty,
797 nested path 'strict $.b[*]' as pb columns (b_id for ordinality, b int path '$' ),
798 nested path 'strict $.c[*]' as pc columns (c_id for ordinality, c int path '$' )
801 n | a | b_id | b | c_id | c
802 ---+----+------+---+------+----
816 -- PASSING arguments are passed to nested paths and their columns' paths
819 generate_series(1, 3) x,
820 generate_series(1, 3) y,
822 '[[1,2,3],[2,3,4,5],[3,4,5,6]]',
823 'strict $[*] ? (@[*] <= $x)'
824 PASSING x AS x, y AS y
826 y text FORMAT JSON PATH '$',
827 NESTED PATH 'strict $[*] ? (@ == $y)'
834 ---+---+--------------+---
835 1 | 1 | [1, 2, 3] | 1
836 2 | 1 | [1, 2, 3] | 1
837 2 | 1 | [2, 3, 4, 5] |
838 3 | 1 | [1, 2, 3] | 1
839 3 | 1 | [2, 3, 4, 5] |
840 3 | 1 | [3, 4, 5, 6] |
841 1 | 2 | [1, 2, 3] | 2
842 2 | 2 | [1, 2, 3] | 2
843 2 | 2 | [2, 3, 4, 5] | 2
844 3 | 2 | [1, 2, 3] | 2
845 3 | 2 | [2, 3, 4, 5] | 2
846 3 | 2 | [3, 4, 5, 6] |
847 1 | 3 | [1, 2, 3] | 3
848 2 | 3 | [1, 2, 3] | 3
849 2 | 3 | [2, 3, 4, 5] | 3
850 3 | 3 | [1, 2, 3] | 3
851 3 | 3 | [2, 3, 4, 5] | 3
852 3 | 3 | [3, 4, 5, 6] | 3
855 -- JSON_TABLE: Test backward parsing with nested paths
856 CREATE VIEW jsonb_table_view_nested AS
859 jsonb 'null', 'lax $[*]' PASSING 1 + 2 AS a, json '"foo"' AS "b c"
862 NESTED PATH '$[1]' AS p1 COLUMNS (
864 NESTED PATH '$[*]' AS "p1 1" COLUMNS (
869 NESTED PATH '$[2]' AS p2 COLUMNS (
870 NESTED PATH '$[*]' AS "p2:1" COLUMNS (
873 NESTED PATH '$[*]' AS p22 COLUMNS (
879 \sv jsonb_table_view_nested
880 CREATE OR REPLACE VIEW public.jsonb_table_view_nested AS
888 'null'::jsonb, '$[*]' AS json_table_path_0
891 '"foo"'::json AS "b c"
894 NESTED PATH '$[1]' AS p1
896 a1 integer PATH '$."a1"',
897 b1 text PATH '$."b1"',
898 NESTED PATH '$[*]' AS "p1 1"
900 a11 text PATH '$."a11"'
903 NESTED PATH '$[2]' AS p2
905 NESTED PATH '$[*]' AS "p2:1"
907 a21 text PATH '$."a21"'
909 NESTED PATH '$[*]' AS p22
911 a22 text PATH '$."a22"'
916 DROP VIEW jsonb_table_view_nested;
917 CREATE TABLE s (js jsonb);
919 ('{"a":{"za":[{"z1": [11,2222]},{"z21": [22, 234,2345]},{"z22": [32, 204,145]}]},"c": 3}'),
920 ('{"a":{"za":[{"z1": [21,4222]},{"z21": [32, 134,1345]}]},"c": 10}');
923 JSON_TABLE(js, '$' PASSING 32 AS x, 13 AS y COLUMNS (
925 NESTED PATH '$.a.za[1]' columns (NESTED PATH '$.z21[*]' COLUMNS (z21 int path '$?(@ >= $"x")' ERROR ON ERROR))
937 -- Parent columns xx1, xx appear before NESTED ones
939 (VALUES (23)) x(x), generate_series(13, 13) y,
940 JSON_TABLE(js, '$' AS c1 PASSING x AS x, y AS y COLUMNS (
941 NESTED PATH '$.a.za[2]' COLUMNS (
942 NESTED PATH '$.z22[*]' as z22 COLUMNS (c int PATH '$')),
943 NESTED PATH '$.a.za[1]' columns (d int[] PATH '$.z21'),
944 NESTED PATH '$.a.za[0]' columns (NESTED PATH '$.z1[*]' as z1 COLUMNS (a int PATH '$')),
946 NESTED PATH '$.a.za[1]' columns (NESTED PATH '$.z21[*]' as z21 COLUMNS (b int PATH '$')),
949 xx1 | xx | c | d | a | b
950 -----+----+-----+---------------+------+------
954 3 | 3 | | {22,234,2345} | |
960 10 | 10 | | {32,134,1345} | |
968 -- Test applying PASSING variables at different nesting levels
970 (VALUES (23)) x(x), generate_series(13, 13) y,
971 JSON_TABLE(js, '$' AS c1 PASSING x AS x, y AS y COLUMNS (
973 NESTED PATH '$.a.za[0].z1[*]' COLUMNS (NESTED PATH '$ ?(@ >= ($"x" -2))' COLUMNS (a int PATH '$')),
974 NESTED PATH '$.a.za[0]' COLUMNS (NESTED PATH '$.z1[*] ? (@ >= ($"x" -2))' COLUMNS (b int PATH '$'))
987 -- Test applying PASSING variable to paths all the levels
990 generate_series(13, 13) y,
991 JSON_TABLE(js, '$' AS c1 PASSING x AS x, y AS y
994 NESTED PATH '$.a.za[1]'
995 COLUMNS (NESTED PATH '$.z21[*]' COLUMNS (b int PATH '$')),
996 NESTED PATH '$.a.za[1] ? (@.z21[*] >= ($"x"-1))' COLUMNS
997 (NESTED PATH '$.z21[*] ? (@ >= ($"y" + 3))' as z22 COLUMNS (a int PATH '$ ? (@ >= ($"y" + 12))')),
998 NESTED PATH '$.a.za[1]' COLUMNS
999 (NESTED PATH '$.z21[*] ? (@ >= ($"y" +121))' as z21 COLUMNS (c int PATH '$ ? (@ > ($"x" +111))'))
1002 -----+------+------+------
1021 ----- test on empty behavior
1022 SELECT sub.* FROM s,
1024 generate_series(13, 13) y,
1025 JSON_TABLE(js, '$' AS c1 PASSING x AS x, y AS y
1028 NESTED PATH '$.a.za[2]' COLUMNS (NESTED PATH '$.z22[*]' as z22 COLUMNS (c int PATH '$')),
1029 NESTED PATH '$.a.za[1]' COLUMNS (d json PATH '$ ? (@.z21[*] == ($"x" -1))'),
1030 NESTED PATH '$.a.za[0]' COLUMNS (NESTED PATH '$.z1[*] ? (@ >= ($"x" -2))' as z1 COLUMNS (a int PATH '$')),
1031 NESTED PATH '$.a.za[1]' COLUMNS
1032 (NESTED PATH '$.z21[*] ? (@ >= ($"y" +121))' as z21 COLUMNS (b int PATH '$ ? (@ > ($"x" +111))' DEFAULT 0 ON EMPTY))
1035 -----+-----+--------------------------+------+------
1039 3 | | {"z21": [22, 234, 2345]} | |
1050 CREATE OR REPLACE VIEW jsonb_table_view7 AS
1051 SELECT sub.* FROM s,
1053 generate_series(13, 13) y,
1054 JSON_TABLE(js, '$' AS c1 PASSING x AS x, y AS y
1057 NESTED PATH '$.a.za[2]' COLUMNS (NESTED PATH '$.z22[*]' as z22 COLUMNS (c int PATH '$' WITHOUT WRAPPER OMIT QUOTES)),
1058 NESTED PATH '$.a.za[1]' COLUMNS (d json PATH '$ ? (@.z21[*] == ($"x" -1))' WITH WRAPPER),
1059 NESTED PATH '$.a.za[0]' COLUMNS (NESTED PATH '$.z1[*] ? (@ >= ($"x" -2))' as z1 COLUMNS (a int PATH '$' KEEP QUOTES)),
1060 NESTED PATH '$.a.za[1]' COLUMNS
1061 (NESTED PATH '$.z21[*] ? (@ >= ($"y" +121))' as z21 COLUMNS (b int PATH '$ ? (@ > ($"x" +111))' DEFAULT 0 ON EMPTY))
1063 \sv jsonb_table_view7
1064 CREATE OR REPLACE VIEW public.jsonb_table_view7 AS
1071 ( VALUES (23)) x(x),
1072 generate_series(13, 13) y(y),
1079 xx1 integer PATH '$."c"',
1080 NESTED PATH '$."a"."za"[2]' AS json_table_path_0
1082 NESTED PATH '$."z22"[*]' AS z22
1084 c integer PATH '$' WITHOUT WRAPPER OMIT QUOTES
1087 NESTED PATH '$."a"."za"[1]' AS json_table_path_1
1089 d json PATH '$?(@."z21"[*] == $"x" - 1)' WITH UNCONDITIONAL WRAPPER KEEP QUOTES
1091 NESTED PATH '$."a"."za"[0]' AS json_table_path_2
1093 NESTED PATH '$."z1"[*]?(@ >= $"x" - 2)' AS z1
1095 a integer PATH '$' WITHOUT WRAPPER KEEP QUOTES
1098 NESTED PATH '$."a"."za"[1]' AS json_table_path_3
1100 NESTED PATH '$."z21"[*]?(@ >= $"y" + 121)' AS z21
1102 b integer PATH '$?(@ > $"x" + 111)' DEFAULT 0 ON EMPTY
1107 DROP VIEW jsonb_table_view7;
1109 -- Prevent ON EMPTY specification on EXISTS columns
1110 SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int exists empty object on empty));
1111 ERROR: syntax error at or near "empty"
1112 LINE 1: ...sonb '1', '$' COLUMNS (a int exists empty object on empty));
1114 -- Test ON ERROR / EMPTY value validity for the function and column types;
1116 SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int) NULL ON ERROR);
1117 ERROR: invalid ON ERROR behavior
1118 LINE 1: ... * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int) NULL ON ER...
1120 DETAIL: Only EMPTY [ ARRAY ] or ERROR is allowed in the top-level ON ERROR clause.
1121 SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int true on empty));
1122 ERROR: invalid ON EMPTY behavior for column "a"
1123 LINE 1: ...T * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int true on em...
1125 DETAIL: Only ERROR, NULL, or DEFAULT expression is allowed in ON EMPTY for scalar columns.
1126 SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int omit quotes true on error));
1127 ERROR: invalid ON ERROR behavior for column "a"
1128 LINE 1: ...N_TABLE(jsonb '1', '$' COLUMNS (a int omit quotes true on er...
1130 DETAIL: Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in ON ERROR for formatted columns.
1131 SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int exists empty object on error));
1132 ERROR: invalid ON ERROR behavior for column "a"
1133 LINE 1: ...M JSON_TABLE(jsonb '1', '$' COLUMNS (a int exists empty obje...
1135 DETAIL: Only ERROR, TRUE, FALSE, or UNKNOWN is allowed in ON ERROR for EXISTS columns.
1136 -- Test JSON_TABLE() column deparsing -- don't emit default ON ERROR / EMPTY
1138 CREATE VIEW json_table_view8 AS SELECT * from JSON_TABLE('"a"', '$' COLUMNS (a text PATH '$'));
1139 \sv json_table_view8;
1140 CREATE OR REPLACE VIEW public.json_table_view8 AS
1143 '"a"'::text, '$' AS json_table_path_0
1148 CREATE VIEW json_table_view9 AS SELECT * from JSON_TABLE('"a"', '$' COLUMNS (a text PATH '$') ERROR ON ERROR);
1149 \sv json_table_view9;
1150 CREATE OR REPLACE VIEW public.json_table_view9 AS
1153 '"a"'::text, '$' AS json_table_path_0
1158 DROP VIEW json_table_view8, json_table_view9;
1159 -- Test JSON_TABLE() deparsing -- don't emit default ON ERROR behavior
1160 CREATE VIEW json_table_view8 AS SELECT * from JSON_TABLE('"a"', '$' COLUMNS (a text PATH '$') EMPTY ON ERROR);
1161 \sv json_table_view8;
1162 CREATE OR REPLACE VIEW public.json_table_view8 AS
1165 '"a"'::text, '$' AS json_table_path_0
1170 CREATE VIEW json_table_view9 AS SELECT * from JSON_TABLE('"a"', '$' COLUMNS (a text PATH '$') EMPTY ARRAY ON ERROR);
1171 \sv json_table_view9;
1172 CREATE OR REPLACE VIEW public.json_table_view9 AS
1175 '"a"'::text, '$' AS json_table_path_0
1180 DROP VIEW json_table_view8, json_table_view9;