Skip to content

Commit 0e5b144

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 c4782c4 commit 0e5b144

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/backend/parser/parse_expr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,8 +4113,9 @@ transformJsonReturning(ParseState *pstate, JsonOutput *output, const char *fname
41134113
if (returning->typid != JSONOID && returning->typid != JSONBOID)
41144114
ereport(ERROR,
41154115
(errcode(ERRCODE_DATATYPE_MISMATCH),
4116-
errmsg("cannot use RETURNING type %s in %s",
4116+
errmsg("cannot use type %s in RETURNING clause of %s",
41174117
format_type_be(returning->typid), fname),
4118+
errhint("Try returning json or jsonb."),
41184119
parser_errposition(pstate, output->typeName->location)));
41194120
}
41204121
else
@@ -4233,7 +4234,7 @@ transformJsonSerializeExpr(ParseState *pstate, JsonSerializeExpr *expr)
42334234
if (typcategory != TYPCATEGORY_STRING)
42344235
ereport(ERROR,
42354236
(errcode(ERRCODE_DATATYPE_MISMATCH),
4236-
errmsg("cannot use RETURNING type %s in %s",
4237+
errmsg("cannot use type %s in RETURNING clause of %s",
42374238
format_type_be(returning->typid),
42384239
"JSON_SERIALIZE()"),
42394240
errhint("Try returning a string type or bytea.")));

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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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)