drop domain if exists djs; create domain djs as jsonb check ( value <> '"11"' ); SELECT JSON_QUERY(jsonb '"aaa"', '$.a' RETURNING djs keep quotes DEFAULT '"11"' ON empty); SELECT JSON_QUERY(jsonb '"aaa"', '$.a' RETURNING djs omit quotes DEFAULT '"11"' ON empty); SELECT JSON_QUERY(jsonb '"11"', '$' RETURNING djs omit quotes DEFAULT '"11"' ON empty);
SELECT JSON_QUERY(jsonb '"aaa"', '$.a' RETURNING jsonb keep quotes DEFAULT '"11"' ON empty); SELECT JSON_QUERY(jsonb '"aaa"', '$.a' RETURNING jsonb omit quotes DEFAULT '"11"' ON empty); SELECT JSON_QUERY(jsonb '"aaa"', '$.a' RETURNING int4range omit quotes DEFAULT '"[1,2]"'::jsonb ON empty); SELECT JSON_QUERY(jsonb '"aaa"', '$.a' RETURNING int4range keep quotes DEFAULT '"[1,2]"'::jsonb ON empty); SELECT JSON_value(jsonb '"aaa"', '$.a' RETURNING int4range DEFAULT '"[1,2]"'::jsonb ON empty); ---------------------------- I found out 2 issues for the above tests. 1. RETURNING types is jsonb/domain over jsonb, default expression does not respect omit/keep quotes, but other RETURNING types do. Maybe this will be fine. 2. domain over jsonb should fail just like domain over other types? RETURNING djs keep quotes DEFAULT '"11"' ON empty should fail as ERROR: could not coerce ON EMPTY expression (DEFAULT) to the RETURNING type DETAIL: value for domain djs violates check constraint "djs_check"" errcode(ERRCODE_CANNOT_COERCE), errmsg("cannot cast behavior expression of type %s to %s", format_type_be(exprType(expr)), format_type_be(returning->typid)), errhint("You will need to cast the expression."), parser_errposition(pstate, exprLocation(expr))); maybe errhint("You will need to explicitly cast the expression to type %s", format_type_be(returning->typid))