]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Split CREATE STATISTICS error reasons out into errdetails
authorJohn Naylor <john.naylor@postgresql.org>
Tue, 7 Apr 2026 04:37:48 +0000 (11:37 +0700)
committerJohn Naylor <john.naylor@postgresql.org>
Tue, 7 Apr 2026 04:37:48 +0000 (11:37 +0700)
Some errmsgs in statscmds.c were phrased as "...cannot be used
because...". Put the reasons into errdetails. While at it, switch
from passive voice to "cannot create..." for the errmsg.

Author: Yugo Nagata <nagata@sraoss.co.jp>
Suggested-by: John Naylor <johncnaylorls@gmail.com>
Discussion: https://postgr.es/m/CANWCAZaZeX0omWNh_ZbD_JVujzYQdRUW8UZOQ4dWh9Sg7OcAow@mail.gmail.com

src/backend/commands/statscmds.c
src/test/regress/expected/stats_ext.out

index eea45106a3ffeaf42ae38b1bef6cf4a05f445aa0..b354723be4435774bf0cdef1923eb36ef0a0ddc6 100644 (file)
@@ -280,8 +280,10 @@ CreateStatistics(CreateStatsStmt *stmt, bool check_rights)
                                if (type->lt_opr == InvalidOid)
                                        ereport(ERROR,
                                                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                                        errmsg("column \"%s\" cannot be used in multivariate statistics because its type %s has no default btree operator class",
-                                                                       attname, format_type_be(attForm->atttypid))));
+                                                        errmsg("cannot create multivariate statistics on column \"%s\"",
+                                                                       attname),
+                                                        errdetail("The type %s has no default btree operator class.",
+                                                                          format_type_be(attForm->atttypid))));
                        }
 
                        /* Treat virtual generated columns as expressions */
@@ -325,8 +327,10 @@ CreateStatistics(CreateStatsStmt *stmt, bool check_rights)
                                if (type->lt_opr == InvalidOid)
                                        ereport(ERROR,
                                                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                                        errmsg("column \"%s\" cannot be used in multivariate statistics because its type %s has no default btree operator class",
-                                                                       get_attname(relid, var->varattno, false), format_type_be(var->vartype))));
+                                                        errmsg("cannot create multivariate statistics on column \"%s\"",
+                                                                       get_attname(relid, var->varattno, false)),
+                                                        errdetail("The type %s has no default btree operator class.",
+                                                                          format_type_be(var->vartype))));
                        }
 
                        /* Treat virtual generated columns as expressions */
@@ -375,8 +379,9 @@ CreateStatistics(CreateStatsStmt *stmt, bool check_rights)
                                if (type->lt_opr == InvalidOid)
                                        ereport(ERROR,
                                                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                                        errmsg("expression cannot be used in multivariate statistics because its type %s has no default btree operator class",
-                                                                       format_type_be(atttype))));
+                                                        errmsg("cannot create multivariate statistics on this expression"),
+                                                        errdetail("The type %s has no default btree operator class.",
+                                                                          format_type_be(atttype))));
                        }
 
                        stxexprs = lappend(stxexprs, expr);
index c6ba2479413c8e68d59a273d96394b57a8e02394..37070c1a896394a1575248e10805d4c5038d26d9 100644 (file)
@@ -99,7 +99,8 @@ CREATE STATISTICS tst (ndistinct) ON (y + z) FROM ext_stats_test;
 ERROR:  cannot specify statistics kinds when building univariate statistics
 -- multivariate statistics without a less-than operator not supported
 CREATE STATISTICS tst (ndistinct) ON x, w from ext_stats_test;
-ERROR:  column "w" cannot be used in multivariate statistics because its type xid has no default btree operator class
+ERROR:  cannot create multivariate statistics on column "w"
+DETAIL:  The type xid has no default btree operator class.
 DROP TABLE ext_stats_test;
 -- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
 CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);