Skip to content

Commit 834fce5

Browse files
committed
Improve error message with JSON_SERIALIZE()
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.horikyota.ntt@gmail.com Backpatch-through: 15
1 parent b2b6c1b commit 834fce5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/backend/parser/parse_expr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4587,8 +4587,9 @@ transformJsonSerializeExpr(ParseState *pstate, JsonSerializeExpr *expr)
45874587
if (typcategory != TYPCATEGORY_STRING)
45884588
ereport(ERROR,
45894589
(errcode(ERRCODE_DATATYPE_MISMATCH),
4590-
errmsg("cannot use RETURNING type %s in JSON_SERIALIZE",
4591-
format_type_be(returning->typid)),
4590+
errmsg("cannot use RETURNING type %s in %s",
4591+
format_type_be(returning->typid),
4592+
"JSON_SERIALIZE()"),
45924593
errhint("Try returning a string type or bytea")));
45934594
}
45944595
}

src/test/regress/expected/sqljson.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ SELECT pg_typeof(JSON_SERIALIZE(NULL));
316316

317317
-- only string types or bytea allowed
318318
SELECT JSON_SERIALIZE('{ "a" : 1 } ' RETURNING jsonb);
319-
ERROR: cannot use RETURNING type jsonb in JSON_SERIALIZE
319+
ERROR: cannot use RETURNING type jsonb in JSON_SERIALIZE()
320320
HINT: Try returning a string type or bytea
321321
EXPLAIN (VERBOSE, COSTS OFF) SELECT JSON_SERIALIZE('{}');
322322
QUERY PLAN

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy