From: Álvaro Herrera <alvherre@kurilemu.de>
To: jian he <jian.universality@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: Kirill Reshke <reshkekirill@gmail.com>
Subject: Re: misleading error message in ProcessUtilitySlow T_CreateStatsStmt
Date: Mon, 20 Oct 2025 18:29:21 +0300
Message-ID: <202510201522.r7i6dr2wm2h7@alvherre.pgsql> (raw)
In-Reply-To: <CACJufxESPwhzVB5xQz6L1bhmjyUMwHrVt7w-NFRB0-vO+FAqzw@mail.gmail.com>
On 2025-Oct-20, jian he wrote:
> @@ -15632,11 +15623,6 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId,
> Oid refRelId, char *cmd,
> querytree_list = lappend(querytree_list, stmt);
> querytree_list = list_concat(querytree_list, afterStmts);
> }
> - else if (IsA(stmt, CreateStatsStmt))
> - querytree_list = lappend(querytree_list,
> - transformStatsStmt(oldRelId,
> - (CreateStatsStmt *) stmt,
> - cmd));
>
> The above "cmd" is the queryString, which is useful for error reporting.
>
> create table t(a int);
> create statistics xxx on (a + 1 is not null) from t;
> alter table t alter column a set data type text;
>
> with patch, v4-0001-Restructure-CreateStatsStmt-parse-analysis-proces.patch
> ERROR: operator does not exist: text + integer
> DETAIL: No operator of that name accepts the given argument types.
> HINT: You might need to add explicit type casts.
>
> In the master branch, the error message also includes the error position.
> ERROR: operator does not exist: text + integer
> LINE 1: alter table t alter column a set data type text;
> ^
> DETAIL: No operator of that name accepts the given argument types.
> HINT: You might need to add explicit type casts.
Interesting, thanks for the example.
I think this example illustrates very well why the 'cmd' is rather
useless here -- note how the error message refers to an operator that
appears nowhere in the query string. The user says "SET DATA TYPE text"
and then we complain about the "text+integer" operator? That makes no
sense and I don't think it's in any way useful.
I think a user-friendly thing we could do is add an errcontext callback
that shows that we're trying to reapply a statistics object. We should
discuss that in a separate thread for a separate patch though, and also
I don't think that thread should prevent this rework from being applied
now. We could add this test scenario to the regression tests though, if
only to show how it would change later.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: alvherre@kurilemu.de, jian.universality@gmail.com, peter@eisentraut.org, tgl@sss.pgh.pa.us, reshkekirill@gmail.com
Subject: Re: misleading error message in ProcessUtilitySlow T_CreateStatsStmt
In-Reply-To: <202510201522.r7i6dr2wm2h7@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox