Improve error message with JSON_SERIALIZE()
authorMichael Paquier <[email protected]>
Mon, 11 Jul 2022 02:20:15 +0000 (11:20 +0900)
committerMichael Paquier <[email protected]>
Mon, 11 Jul 2022 02:20:15 +0000 (11:20 +0900)
The error message introduced in 3c633f3 can share the same format string
with an existing message used for JSON(), reducing the translation
effort.

Author: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20220708.154135.2123613118233840495[email protected]
Backpatch-through: 15

src/backend/parser/parse_expr.c
src/test/regress/expected/sqljson.out

index efcf1cd5abc0a31bc2ab04f3eee0b7ca6566c1a3..1dbdba93daae4e5955e4a9202da8cf6b8a1f5e18 100644 (file)
@@ -4587,8 +4587,9 @@ transformJsonSerializeExpr(ParseState *pstate, JsonSerializeExpr *expr)
            if (typcategory != TYPCATEGORY_STRING)
                ereport(ERROR,
                        (errcode(ERRCODE_DATATYPE_MISMATCH),
-                        errmsg("cannot use RETURNING type %s in JSON_SERIALIZE",
-                               format_type_be(returning->typid)),
+                        errmsg("cannot use RETURNING type %s in %s",
+                               format_type_be(returning->typid),
+                               "JSON_SERIALIZE()"),
                         errhint("Try returning a string type or bytea")));
        }
    }
index be27bce9d32032b9d1661e6bf0391904d1b5d610..aae4ba4939008ffd23dc10b2d46d9fde3712a88a 100644 (file)
@@ -316,7 +316,7 @@ SELECT pg_typeof(JSON_SERIALIZE(NULL));
 
 -- only string types or bytea allowed
 SELECT JSON_SERIALIZE('{ "a" : 1 } ' RETURNING jsonb);
-ERROR:  cannot use RETURNING type jsonb in JSON_SERIALIZE
+ERROR:  cannot use RETURNING type jsonb in JSON_SERIALIZE()
 HINT:  Try returning a string type or bytea
 EXPLAIN (VERBOSE, COSTS OFF) SELECT JSON_SERIALIZE('{}');
                      QUERY PLAN