Hello Michael and Tom,
22.09.2026 13:49, Michael Paquier wrote:
As a whole, that looks OK, so applied on HEAD. I did not look at
0002.
Let me share the following set of other internal errors:
1)
CREATE TABLE t AS SELECT ''::text a;
CREATE INDEX brinidx ON t USING brin
(a text_bloom_ops(n_distinct_per_range = -1.0));
ERROR: XX000: the bloom filter is too large (44629 > 8144)
LOCATION: bloom_init, brin_bloom.c:
-> ERRCODE_PROGRAM_LIMIT_EXCEEDED
2)
SELECT pg_identify_object_as_address('1'::regclass, 1, 1);
ERROR: XX000: unsupported object class: 1
LOCATION: getObjectTypeDescription, objectaddress.c:4731
-> ERRCODE_INVALID_PARAMETER_VALUE
3)
SELECT pg_get_acl('1'::regclass, 1, 0);
ERROR: XX000: unrecognized class ID: 1
LOCATION: get_object_property_data, objectaddress.c:2821
-> ERRCODE_INVALID_PARAMETER_VALUE
4)
SELECT jsonb_to_tsvector('{}', '[{}]'::jsonb);
ERROR: XX000: unexpected end of flag array
LOCATION: parse_jsonb_index_flags, jsonfuncs.c:5614
-> ERRCODE_INVALID_PARAMETER_VALUE
5)
CREATE PROCEDURE p(INOUT a integer) LANGUAGE sql
AS 'SELECT 1 WHERE false;';
CALL p(1);
ERROR: XX000: procedure returned null record
LOCATION: ExecuteCallStmt, functioncmds.c:2351
-> ERRCODE_INVALID_OBJECT_DEFINITION
6)
CREATE EXTENSION dblink;
CREATE FUNCTION connection_parameters() RETURNS text LANGUAGE SQL AS
$f$ SELECT $$dbname='$$||current_database()||$$'
port=$$||current_setting('port'); $f$;
SELECT dblink_connect('myconn',connection_parameters());
SELECT * FROM dblink_send_query('myconn', 'SELECT 1');
SELECT * FROM dblink('myconn', 'SELECT 2') AS t(i int);
ERROR: XX000: could not send query: another command is already in progress
LOCATION: storeQueryResult, dblink.c:1103
-> ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE
Please look at the attached patch which defines these error codes.
Best regards,
Alexanderdiff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 9613f881985..29c19e0017f 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -1105,7 +1105,9 @@ storeQueryResult(storeInfo *sinfo, PGconn *conn, const char *sql)
PGresult *res;
if (!PQsendQuery(conn, sql))
- elog(ERROR, "could not send query: %s", pchomp(PQerrorMessage(conn)));
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("could not send query: %s", pchomp(PQerrorMessage(conn)))));
if (!PQsetSingleRowMode(conn)) /* shouldn't fail */
elog(ERROR, "failed to set single-row mode for dblink query");
diff --git a/src/backend/access/brin/brin_bloom.c b/src/backend/access/brin/brin_bloom.c
index 5558a2edea5..788d89bbe82 100644
--- a/src/backend/access/brin/brin_bloom.c
+++ b/src/backend/access/brin/brin_bloom.c
@@ -342,8 +342,10 @@ bloom_init(int ndistinct, double false_positive_rate)
* filters that are small individually, but too large when combined.
*/
if (nbytes > BloomMaxFilterSize)
- elog(ERROR, "the bloom filter is too large (%d > %zu)", nbytes,
- BloomMaxFilterSize);
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("the bloom filter is too large (%d > %zu)", nbytes,
+ BloomMaxFilterSize)));
/*
* We allocate the whole filter. Most of it is going to be 0 bits, so the
diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 09c9c751133..75aa4b9e714 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -2819,7 +2819,8 @@ get_object_property_data(Oid class_id)
}
ereport(ERROR,
- (errmsg_internal("unrecognized class ID: %u", class_id)));
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("unrecognized class ID: %u", class_id)));
return NULL; /* keep MSC compiler happy */
}
@@ -4728,7 +4729,9 @@ getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
break;
default:
- elog(ERROR, "unsupported object class: %u", object->classId);
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("unsupported object class: %u", object->classId)));
}
/* the result can never be empty */
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 4d46013d7de..1f4c0b156b0 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -2348,7 +2348,9 @@ ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver
TupleTableSlot *slot;
if (fcinfo->isnull)
- elog(ERROR, "procedure returned null record");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("procedure returned null record")));
/*
* Ensure there's an active snapshot whilst we execute whatever's
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index adbafd0ecd3..4e4424f98d7 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -5611,7 +5611,9 @@ parse_jsonb_index_flags(Jsonb *jb)
/* expect end of array now */
if (type != WJB_END_ARRAY)
- elog(ERROR, "unexpected end of flag array");
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("unexpected end of flag array")));
/* get final WJB_DONE and free iterator */
type = JsonbIteratorNext(&it, &v, false);