mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Report specific SQLSTATEs for stats restore errors
The pg_restore_*_stats() functions could report SQLSTATE XX000 for invalid variadic arguments, such as an unmatched name/value pair, a NULL argument name, or a non-text argument name. Attribute and extended statistics restores could also report XX000 when the supplied statistics exceed the number of slots PostgreSQL can store. These are not internal errors. They result from invalid caller input or a PostgreSQL implementation limit, but the lack of specific SQLSTATEs made clients treat them as internal errors. Assign appropriate SQLSTATEs to these errors so that applications and tests can classify them correctly. Backpatch to v19, but no further; changing ERRCODE assignments in released stable branches doesn't seem like a good idea. Bug: #19629 Reported-by: Zheng Wang <hackerzheng666@gmail.com> Reported-by: Yanjie Zhao Reported-by: Yiyang Liu Author: Fujii Masao <masao.fujii@gmail.com> Discussion: https://postgr.es/m/19629-76babc04b683594d@postgresql.org Backpatch-through: 19
This commit is contained in:
@@ -369,8 +369,9 @@ stats_fill_fcinfo_from_arg_pairs(FunctionCallInfo pairs_fcinfo,
|
||||
|
||||
if (nargs % 2 != 0)
|
||||
ereport(ERROR,
|
||||
errmsg("variadic arguments must be name/value pairs"),
|
||||
errhint("Provide an even number of variadic arguments that can be divided into pairs."));
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("variadic arguments must be name/value pairs"),
|
||||
errhint("Provide an even number of variadic arguments that can be divided into pairs.")));
|
||||
|
||||
/*
|
||||
* For each argument name/value pair, find corresponding positional
|
||||
@@ -384,11 +385,13 @@ stats_fill_fcinfo_from_arg_pairs(FunctionCallInfo pairs_fcinfo,
|
||||
|
||||
if (argnulls[i])
|
||||
ereport(ERROR,
|
||||
(errmsg("name at variadic position %d is null", i + 1)));
|
||||
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
|
||||
errmsg("name at variadic position %d is null", i + 1)));
|
||||
|
||||
if (types[i] != TEXTOID)
|
||||
ereport(ERROR,
|
||||
(errmsg("name at variadic position %d has type %s, expected type %s",
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("name at variadic position %d has type %s, expected type %s",
|
||||
i + 1, format_type_be(types[i]),
|
||||
format_type_be(TEXTOID))));
|
||||
|
||||
@@ -653,7 +656,8 @@ statatt_set_slot(Datum *values, bool *nulls, bool *replaces,
|
||||
|
||||
if (slotidx >= STATISTIC_NUM_SLOTS)
|
||||
ereport(ERROR,
|
||||
(errmsg("maximum number of statistics slots exceeded: %d",
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("maximum number of statistics slots exceeded: %d",
|
||||
slotidx + 1)));
|
||||
|
||||
stakind_attnum = Anum_pg_statistic_stakind1 - 1 + slotidx;
|
||||
|
||||
Reference in New Issue
Block a user