At Thu, 07 Jul 2022 21:46:12 +0000, Andrew Dunstan <[email protected]> wrote
in
> Only allow returning string types or bytea from json_serialize
I noticed that this introcues the following error message.
+ errmsg("cannot use RETURNING type %s in JSON_SERIALIZE"
+
format_type_be(returning->typid)),
However, the same file has the following error message.
> errmsg("cannot use RETURNING type %s in %s",
> format_type_be(returning->typid),
> fname),
So, couldn't we share the format string to reduce translatable
messages?
And, the other messages are
cannot use RETURNING type %s in JSON_SCALAR(), and
cannot use RETURNING type %s in JSON()
So, I think this should not be
cannot use RETURNING type %s in JSON_SERIALIZE
, but should be
cannot use RETURNING type %s in JSON_SERIALIZE()
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
>From 3d62f30c9e112e52190b638569de8fc69e287ddb Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <[email protected]>
Date: Fri, 8 Jul 2022 15:21:05 +0900
Subject: [PATCH] Fix an error message
Fix an error message in accordance to the simlar messages. The
message can share the same format string with an existing message, so
use it to reduce the number of translatable error messages.
---
src/backend/parser/parse_expr.c | 5 +++--
src/test/regress/expected/sqljson.out | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index efcf1cd5ab..1dbdba93da 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -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")));
}
}
diff --git a/src/test/regress/expected/sqljson.out b/src/test/regress/expected/sqljson.out
index be27bce9d3..aae4ba4939 100644
--- a/src/test/regress/expected/sqljson.out
+++ b/src/test/regress/expected/sqljson.out
@@ -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
--
2.31.1