@@ -758,6 +758,53 @@ FROM
758758 4 | 4 | [4]
759759(25 rows)
760760
761+ -- Extension: record types returning
762+ CREATE TYPE sqljsonb_rec AS (a int, t text, js json, jb jsonb, jsa json[]);
763+ CREATE TYPE sqljsonb_reca AS (reca sqljsonb_rec[]);
764+ SELECT JSON_QUERY(jsonb '[{"a": 1, "b": "foo", "t": "aaa", "js": [1, "2", {}], "jb": {"x": [1, "2", {}]}}, {"a": 2}]', '$[0]' RETURNING sqljsonb_rec);
765+ json_query
766+ -----------------------------------------------------
767+ (1,aaa,"[1, ""2"", {}]","{""x"": [1, ""2"", {}]}",)
768+ (1 row)
769+
770+ SELECT * FROM unnest((JSON_QUERY(jsonb '{"jsa": [{"a": 1, "b": ["foo"]}, {"a": 2, "c": {}}, 123]}', '$' RETURNING sqljsonb_rec)).jsa);
771+ unnest
772+ ------------------------
773+ {"a": 1, "b": ["foo"]}
774+ {"a": 2, "c": {}}
775+ 123
776+ (3 rows)
777+
778+ SELECT * FROM unnest((JSON_QUERY(jsonb '{"reca": [{"a": 1, "t": ["foo", []]}, {"a": 2, "jb": [{}, true]}]}', '$' RETURNING sqljsonb_reca)).reca);
779+ a | t | js | jb | jsa
780+ ---+-------------+----+------------+-----
781+ 1 | ["foo", []] | | |
782+ 2 | | | [{}, true] |
783+ (2 rows)
784+
785+ -- Extension: array types returning
786+ SELECT JSON_QUERY(jsonb '[1,2,null,"3"]', '$[*]' RETURNING int[] WITH WRAPPER);
787+ json_query
788+ --------------
789+ {1,2,NULL,3}
790+ (1 row)
791+
792+ SELECT * FROM unnest(JSON_QUERY(jsonb '[{"a": 1, "t": ["foo", []]}, {"a": 2, "jb": [{}, true]}]', '$' RETURNING sqljsonb_rec[]));
793+ a | t | js | jb | jsa
794+ ---+-------------+----+------------+-----
795+ 1 | ["foo", []] | | |
796+ 2 | | | [{}, true] |
797+ (2 rows)
798+
799+ -- Extension: domain types returning
800+ SELECT JSON_QUERY(jsonb '{"a": 1}', '$.a' RETURNING sqljsonb_int_not_null);
801+ json_query
802+ ------------
803+ 1
804+ (1 row)
805+
806+ SELECT JSON_QUERY(jsonb '{"a": 1}', '$.b' RETURNING sqljsonb_int_not_null);
807+ ERROR: domain sqljsonb_int_not_null does not allow null values
761808-- Test constraints
762809CREATE TABLE test_jsonb_constraints (
763810 js text,
0 commit comments