Skip to content

Commit d7905aa

Browse files
committed
Fix error message wording
The originals are ambiguous and a bit out of style. Reviewed-by: Amit Langote <amitlangote09@gmail.com> Discussion: https://postgr.es/m/202412141243.efesjyyvzxsz@alvherre.pgsql
1 parent e998901 commit d7905aa

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/backend/parser/parse_expr.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -4115,8 +4115,9 @@ transformJsonReturning(ParseState *pstate, JsonOutput *output, const char *fname
41154115
if (returning->typid != JSONOID && returning->typid != JSONBOID)
41164116
ereport(ERROR,
41174117
(errcode(ERRCODE_DATATYPE_MISMATCH),
4118-
errmsg("cannot use RETURNING type %s in %s",
4118+
errmsg("cannot use type %s in RETURNING clause of %s",
41194119
format_type_be(returning->typid), fname),
4120+
errhint("Try returning json or jsonb."),
41204121
parser_errposition(pstate, output->typeName->location)));
41214122
}
41224123
else
@@ -4235,7 +4236,7 @@ transformJsonSerializeExpr(ParseState *pstate, JsonSerializeExpr *expr)
42354236
if (typcategory != TYPCATEGORY_STRING)
42364237
ereport(ERROR,
42374238
(errcode(ERRCODE_DATATYPE_MISMATCH),
4238-
errmsg("cannot use RETURNING type %s in %s",
4239+
errmsg("cannot use type %s in RETURNING clause of %s",
42394240
format_type_be(returning->typid),
42404241
"JSON_SERIALIZE()"),
42414242
errhint("Try returning a string type or bytea.")));

src/interfaces/ecpg/test/expected/sql-sqljson.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,12 @@ SQL error: null value without indicator on line 84
240240
[NO_PID]: sqlca: code: 0, state: 00000
241241
[NO_PID]: ecpg_execute on line 99: using PQexec
242242
[NO_PID]: sqlca: code: 0, state: 00000
243-
[NO_PID]: ecpg_check_PQresult on line 99: bad response - ERROR: cannot use RETURNING type jsonb in JSON_SERIALIZE()
243+
[NO_PID]: ecpg_check_PQresult on line 99: bad response - ERROR: cannot use type jsonb in RETURNING clause of JSON_SERIALIZE()
244244
HINT: Try returning a string type or bytea.
245245
[NO_PID]: sqlca: code: 0, state: 00000
246-
[NO_PID]: raising sqlstate 42804 (sqlcode -400): cannot use RETURNING type jsonb in JSON_SERIALIZE() on line 99
246+
[NO_PID]: raising sqlstate 42804 (sqlcode -400): cannot use type jsonb in RETURNING clause of JSON_SERIALIZE() on line 99
247247
[NO_PID]: sqlca: code: -400, state: 42804
248-
SQL error: cannot use RETURNING type jsonb in JSON_SERIALIZE() on line 99
248+
SQL error: cannot use type jsonb in RETURNING clause of JSON_SERIALIZE() on line 99
249249
[NO_PID]: ecpg_execute on line 102: query: with val ( js ) as ( values ( '{ "a": 1, "b": [{ "a": 1, "b": 0, "a": 2 }] }' ) ) select js is json "IS JSON" , js is not json "IS NOT JSON" , js is json value "IS VALUE" , js is json object "IS OBJECT" , js is json array "IS ARRAY" , js is json scalar "IS SCALAR" , js is json without unique keys "WITHOUT UNIQUE" , js is json with unique keys "WITH UNIQUE" from val; with 0 parameter(s) on connection ecpg1_regression
250250
[NO_PID]: sqlca: code: 0, state: 00000
251251
[NO_PID]: ecpg_execute on line 102: using PQexec

src/test/regress/expected/sqljson.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ SELECT pg_typeof(JSON_SERIALIZE(NULL));
272272

273273
-- only string types or bytea allowed
274274
SELECT JSON_SERIALIZE('{ "a" : 1 } ' RETURNING jsonb);
275-
ERROR: cannot use RETURNING type jsonb in JSON_SERIALIZE()
275+
ERROR: cannot use type jsonb in RETURNING clause of JSON_SERIALIZE()
276276
HINT: Try returning a string type or bytea.
277277
EXPLAIN (VERBOSE, COSTS OFF) SELECT JSON_SERIALIZE('{}');
278278
QUERY PLAN

0 commit comments

Comments
 (0)