Skip to content

Commit 2bb969f

Browse files
committed
Refactor/reword some error messages to avoid duplicates
Also, remove brackets around "EMPTY [ ARRAY ]". An error message is not the place to state that a keyword is optional. Backpatch to 17.
1 parent 22b4a1b commit 2bb969f

File tree

5 files changed

+74
-34
lines changed

5 files changed

+74
-34
lines changed

src/backend/executor/execExprInterp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4660,13 +4660,17 @@ ExecEvalJsonCoercionFinish(ExprState *state, ExprEvalStep *op)
46604660
if (DatumGetBool(jsestate->error.value))
46614661
ereport(ERROR,
46624662
(errcode(ERRCODE_DATATYPE_MISMATCH),
4663-
errmsg("could not coerce ON ERROR expression (%s) to the RETURNING type",
4663+
/*- translator: first %s is a SQL/JSON clause (e.g. ON ERROR) */
4664+
errmsg("could not coerce %s expression (%s) to the RETURNING type",
4665+
"ON ERROR",
46644666
GetJsonBehaviorValueString(jsestate->jsexpr->on_error)),
46654667
errdetail("%s", jsestate->escontext.error_data->message)));
46664668
else if (DatumGetBool(jsestate->empty.value))
46674669
ereport(ERROR,
46684670
(errcode(ERRCODE_DATATYPE_MISMATCH),
4669-
errmsg("could not coerce ON EMPTY expression (%s) to the RETURNING type",
4671+
/*- translator: first %s is a SQL/JSON clause (e.g. ON ERROR) */
4672+
errmsg("could not coerce %s expression (%s) to the RETURNING type",
4673+
"ON EMPTY",
46704674
GetJsonBehaviorValueString(jsestate->jsexpr->on_empty)),
46714675
errdetail("%s", jsestate->escontext.error_data->message)));
46724676

src/backend/parser/parse_expr.c

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,8 @@ transformAExprNullIf(ParseState *pstate, A_Expr *a)
10991099
if (result->opresulttype != BOOLOID)
11001100
ereport(ERROR,
11011101
(errcode(ERRCODE_DATATYPE_MISMATCH),
1102-
errmsg("NULLIF requires = operator to yield boolean"),
1102+
/* translator: %s is name of a SQL construct, eg NULLIF */
1103+
errmsg("%s requires = operator to yield boolean", "NULLIF"),
11031104
parser_errposition(pstate, a->location)));
11041105
if (result->opretset)
11051106
ereport(ERROR,
@@ -3060,7 +3061,9 @@ make_distinct_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree,
30603061
if (((OpExpr *) result)->opresulttype != BOOLOID)
30613062
ereport(ERROR,
30623063
(errcode(ERRCODE_DATATYPE_MISMATCH),
3063-
errmsg("IS DISTINCT FROM requires = operator to yield boolean"),
3064+
/* translator: %s is name of a SQL construct, eg NULLIF */
3065+
errmsg("%s requires = operator to yield boolean",
3066+
"IS DISTINCT FROM"),
30643067
parser_errposition(pstate, location)));
30653068
if (((OpExpr *) result)->opretset)
30663069
ereport(ERROR,
@@ -4326,15 +4329,22 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
43264329
if (func->column_name == NULL)
43274330
ereport(ERROR,
43284331
errcode(ERRCODE_SYNTAX_ERROR),
4329-
errmsg("invalid ON EMPTY behavior"),
4330-
errdetail("Only ERROR, NULL, EMPTY [ ARRAY ], EMPTY OBJECT, or DEFAULT expression is allowed in ON EMPTY for JSON_QUERY()."),
4332+
/*- translator: %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4333+
errmsg("invalid %s behavior", "ON EMPTY"),
4334+
/*- translator: first %s is name of a SQL/JSON clause (eg. ON EMPTY),
4335+
second %s is a SQL/JSON function name (e.g. JSON_QUERY) */
4336+
errdetail("Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in %s for %s.",
4337+
"ON EMPTY", "JSON_QUERY()"),
43314338
parser_errposition(pstate, func->on_empty->location));
43324339
else
43334340
ereport(ERROR,
43344341
errcode(ERRCODE_SYNTAX_ERROR),
4335-
errmsg("invalid ON EMPTY behavior for column \"%s\"",
4336-
func->column_name),
4337-
errdetail("Only ERROR, NULL, EMPTY [ ARRAY ], EMPTY OBJECT, or DEFAULT expression is allowed in ON EMPTY for formatted columns."),
4342+
/*- translator: first %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4343+
errmsg("invalid %s behavior for column \"%s\"",
4344+
"ON EMPTY", func->column_name),
4345+
/*- translator: %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4346+
errdetail("Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in %s for formatted columns.",
4347+
"ON EMPTY"),
43384348
parser_errposition(pstate, func->on_empty->location));
43394349
}
43404350
if (func->on_error != NULL &&
@@ -4348,15 +4358,22 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
43484358
if (func->column_name == NULL)
43494359
ereport(ERROR,
43504360
errcode(ERRCODE_SYNTAX_ERROR),
4351-
errmsg("invalid ON ERROR behavior"),
4352-
errdetail("Only ERROR, NULL, EMPTY [ ARRAY ], EMPTY OBJECT, or DEFAULT expression is allowed in ON ERROR for JSON_QUERY()."),
4361+
/*- translator: %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4362+
errmsg("invalid %s behavior", "ON ERROR"),
4363+
/*- translator: first %s is name of a SQL/JSON clause (eg. ON EMPTY),
4364+
second %s is a SQL/JSON function name (e.g. JSON_QUERY) */
4365+
errdetail("Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in %s for %s.",
4366+
"ON ERROR", "JSON_QUERY()"),
43534367
parser_errposition(pstate, func->on_error->location));
43544368
else
43554369
ereport(ERROR,
43564370
errcode(ERRCODE_SYNTAX_ERROR),
4357-
errmsg("invalid ON ERROR behavior for column \"%s\"",
4358-
func->column_name),
4359-
errdetail("Only ERROR, NULL, EMPTY [ ARRAY ], EMPTY OBJECT, or DEFAULT expression is allowed in ON ERROR for formatted columns."),
4371+
/*- translator: first %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4372+
errmsg("invalid %s behavior for column \"%s\"",
4373+
"ON ERROR", func->column_name),
4374+
/*- translator: %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4375+
errdetail("Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in %s for formatted columns.",
4376+
"ON ERROR"),
43604377
parser_errposition(pstate, func->on_error->location));
43614378
}
43624379
}
@@ -4372,15 +4389,20 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
43724389
if (func->column_name == NULL)
43734390
ereport(ERROR,
43744391
errcode(ERRCODE_SYNTAX_ERROR),
4375-
errmsg("invalid ON ERROR behavior"),
4376-
errdetail("Only ERROR, TRUE, FALSE, or UNKNOWN is allowed in ON ERROR for JSON_EXISTS()."),
4392+
/*- translator: %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4393+
errmsg("invalid %s behavior", "ON ERROR"),
4394+
errdetail("Only ERROR, TRUE, FALSE, or UNKNOWN is allowed in %s for %s.",
4395+
"ON ERROR", "JSON_EXISTS()"),
43774396
parser_errposition(pstate, func->on_error->location));
43784397
else
43794398
ereport(ERROR,
43804399
errcode(ERRCODE_SYNTAX_ERROR),
4381-
errmsg("invalid ON ERROR behavior for column \"%s\"",
4382-
func->column_name),
4383-
errdetail("Only ERROR, TRUE, FALSE, or UNKNOWN is allowed in ON ERROR for EXISTS columns."),
4400+
/*- translator: first %s is name a SQL/JSON clause (eg. ON EMPTY) */
4401+
errmsg("invalid %s behavior for column \"%s\"",
4402+
"ON ERROR", func->column_name),
4403+
/*- translator: %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4404+
errdetail("Only ERROR, TRUE, FALSE, or UNKNOWN is allowed in %s for EXISTS columns.",
4405+
"ON ERROR"),
43844406
parser_errposition(pstate, func->on_error->location));
43854407
}
43864408
if (func->op == JSON_VALUE_OP)
@@ -4393,15 +4415,22 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
43934415
if (func->column_name == NULL)
43944416
ereport(ERROR,
43954417
errcode(ERRCODE_SYNTAX_ERROR),
4396-
errmsg("invalid ON EMPTY behavior"),
4397-
errdetail("Only ERROR, NULL, or DEFAULT expression is allowed in ON EMPTY for JSON_VALUE()."),
4418+
/*- translator: %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4419+
errmsg("invalid %s behavior", "ON EMPTY"),
4420+
/*- translator: first %s is name of a SQL/JSON clause (eg. ON EMPTY),
4421+
second %s is a SQL/JSON function name (e.g. JSON_QUERY) */
4422+
errdetail("Only ERROR, NULL, or DEFAULT expression is allowed in %s for %s.",
4423+
"ON EMPTY", "JSON_VALUE()"),
43984424
parser_errposition(pstate, func->on_empty->location));
43994425
else
44004426
ereport(ERROR,
44014427
errcode(ERRCODE_SYNTAX_ERROR),
4402-
errmsg("invalid ON EMPTY behavior for column \"%s\"",
4403-
func->column_name),
4404-
errdetail("Only ERROR, NULL, or DEFAULT expression is allowed in ON EMPTY for scalar columns."),
4428+
/*- translator: first %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4429+
errmsg("invalid %s behavior for column \"%s\"",
4430+
"ON EMPTY", func->column_name),
4431+
/*- translator: %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4432+
errdetail("Only ERROR, NULL, or DEFAULT expression is allowed in %s for scalar columns.",
4433+
"ON EMPTY"),
44054434
parser_errposition(pstate, func->on_empty->location));
44064435
}
44074436
if (func->on_error != NULL &&
@@ -4412,15 +4441,22 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
44124441
if (func->column_name == NULL)
44134442
ereport(ERROR,
44144443
errcode(ERRCODE_SYNTAX_ERROR),
4415-
errmsg("invalid ON ERROR behavior"),
4416-
errdetail("Only ERROR, NULL, or DEFAULT expression is allowed in ON ERROR for JSON_VALUE()."),
4444+
/*- translator: %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4445+
errmsg("invalid %s behavior", "ON ERROR"),
4446+
/*- translator: first %s is name of a SQL/JSON clause (eg. ON EMPTY),
4447+
second %s is a SQL/JSON function name (e.g. JSON_QUERY) */
4448+
errdetail("Only ERROR, NULL, or DEFAULT expression is allowed in %s for %s.",
4449+
"ON ERROR", "JSON_VALUE()"),
44174450
parser_errposition(pstate, func->on_error->location));
44184451
else
44194452
ereport(ERROR,
44204453
errcode(ERRCODE_SYNTAX_ERROR),
4421-
errmsg("invalid ON ERROR behavior for column \"%s\"",
4422-
func->column_name),
4423-
errdetail("Only ERROR, NULL, or DEFAULT expression is allowed in ON ERROR for scalar columns."),
4454+
/*- translator: first %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4455+
errmsg("invalid %s behavior for column \"%s\"",
4456+
"ON ERROR", func->column_name),
4457+
/*- translator: %s is name of a SQL/JSON clause (eg. ON EMPTY) */
4458+
errdetail("Only ERROR, NULL, or DEFAULT expression is allowed in %s for scalar columns.",
4459+
"ON ERROR"),
44244460
parser_errposition(pstate, func->on_error->location));
44254461
}
44264462
}

src/backend/parser/parse_jsontable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ transformJsonTable(ParseState *pstate, JsonTable *jt)
9191
jt->on_error->btype != JSON_BEHAVIOR_EMPTY_ARRAY)
9292
ereport(ERROR,
9393
errcode(ERRCODE_SYNTAX_ERROR),
94-
errmsg("invalid ON ERROR behavior"),
94+
errmsg("invalid %s behavior", "ON ERROR"),
9595
errdetail("Only EMPTY [ ARRAY ] or ERROR is allowed in the top-level ON ERROR clause."),
9696
parser_errposition(pstate, jt->on_error->location));
9797

@@ -292,7 +292,7 @@ transformJsonTableColumns(JsonTableParseContext *cxt, List *columns,
292292
if (ordinality_found)
293293
ereport(ERROR,
294294
(errcode(ERRCODE_SYNTAX_ERROR),
295-
errmsg("cannot use more than one FOR ORDINALITY column"),
295+
errmsg("only one FOR ORDINALITY column is allowed"),
296296
parser_errposition(pstate, rawc->location)));
297297
ordinality_found = true;
298298
colexpr = NULL;

src/test/regress/expected/sqljson_jsontable.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ DROP VIEW jsonb_table_view6;
489489
DROP DOMAIN jsonb_test_domain;
490490
-- JSON_TABLE: only one FOR ORDINALITY columns allowed
491491
SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (id FOR ORDINALITY, id2 FOR ORDINALITY, a int PATH '$.a' ERROR ON EMPTY)) jt;
492-
ERROR: cannot use more than one FOR ORDINALITY column
492+
ERROR: only one FOR ORDINALITY column is allowed
493493
LINE 1: ..._TABLE(jsonb '1', '$' COLUMNS (id FOR ORDINALITY, id2 FOR OR...
494494
^
495495
SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (id FOR ORDINALITY, a int PATH '$' ERROR ON EMPTY)) jt;
@@ -1126,7 +1126,7 @@ SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int omit quotes true on error
11261126
ERROR: invalid ON ERROR behavior for column "a"
11271127
LINE 1: ...N_TABLE(jsonb '1', '$' COLUMNS (a int omit quotes true on er...
11281128
^
1129-
DETAIL: Only ERROR, NULL, EMPTY [ ARRAY ], EMPTY OBJECT, or DEFAULT expression is allowed in ON ERROR for formatted columns.
1129+
DETAIL: Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in ON ERROR for formatted columns.
11301130
SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int exists empty object on error));
11311131
ERROR: invalid ON ERROR behavior for column "a"
11321132
LINE 1: ...M JSON_TABLE(jsonb '1', '$' COLUMNS (a int exists empty obje...

src/test/regress/expected/sqljson_queryfuncs.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ SELECT JSON_QUERY(jsonb '1', '$' TRUE ON ERROR);
13841384
ERROR: invalid ON ERROR behavior
13851385
LINE 1: SELECT JSON_QUERY(jsonb '1', '$' TRUE ON ERROR);
13861386
^
1387-
DETAIL: Only ERROR, NULL, EMPTY [ ARRAY ], EMPTY OBJECT, or DEFAULT expression is allowed in ON ERROR for JSON_QUERY().
1387+
DETAIL: Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in ON ERROR for JSON_QUERY().
13881388
-- Test implicit coercion to a domain over fixed-length type specified in
13891389
-- RETURNING
13901390
CREATE DOMAIN queryfuncs_char2 AS char(2);

0 commit comments

Comments
 (0)