Adjust error message for CREATE STATISTICS to account for expressions

Started by Yugo Nagata21 days ago16 messageshackers
Jump to latest
#1Yugo Nagata
nagata@sraoss.co.jp

Hi,

I've attached a patch to adjust the error message for CREATE STATISTICS
to account for expressions.

Previously, when attempting to create extended statistics on a single column,
the following error is raised.

ERROR: extended statistics require at least 2 columns

However, this message assumed only columns. In reality, an expression on a
single column is also allowed, so two columns are not necessarily required.
Thgis patch updates the message to:

ERROR: extended statistics require at least 2 columns or an expression

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

Attachments:

Adjust_error_message_for_CREATE_STATISTICS.patchtext/x-diff; name=Adjust_error_message_for_CREATE_STATISTICS.patchDownload+1-1
#2John Naylor
john.naylor@enterprisedb.com
In reply to: Yugo Nagata (#1)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Tue, Mar 24, 2026 at 6:34 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:

Hi,

I've attached a patch to adjust the error message for CREATE STATISTICS
to account for expressions.

Previously, when attempting to create extended statistics on a single column,
the following error is raised.

ERROR: extended statistics require at least 2 columns

However, this message assumed only columns. In reality, an expression on a
single column is also allowed, so two columns are not necessarily required.
Thgis patch updates the message to:

ERROR: extended statistics require at least 2 columns or an expression

I'm ambivalent about this. Instead of trying to document all the
possible valid possibilities (which may get out of date again), maybe
we can say that it's not allowed on a single column?

--
John Naylor
Amazon Web Services

#3Yugo Nagata
nagata@sraoss.co.jp
In reply to: John Naylor (#2)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Wed, 25 Mar 2026 08:24:40 +0700
John Naylor <johncnaylorls@gmail.com> wrote:

On Tue, Mar 24, 2026 at 6:34 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:

Hi,

I've attached a patch to adjust the error message for CREATE STATISTICS
to account for expressions.

Previously, when attempting to create extended statistics on a single column,
the following error is raised.

ERROR: extended statistics require at least 2 columns

However, this message assumed only columns. In reality, an expression on a
single column is also allowed, so two columns are not necessarily required.
Thgis patch updates the message to:

ERROR: extended statistics require at least 2 columns or an expression

I'm ambivalent about this. Instead of trying to document all the
possible valid possibilities (which may get out of date again), maybe
we can say that it's not allowed on a single column?

Thank you for the suggestion. I agree that this is a simpler approach,
so I've attached a revised patch.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

Attachments:

v2-Adjust_error_message_for_CREATE_STATISTICS.patchtext/x-diff; name=v2-Adjust_error_message_for_CREATE_STATISTICS.patchDownload+1-1
#4John Naylor
john.naylor@enterprisedb.com
In reply to: Yugo Nagata (#3)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Wed, Mar 25, 2026 at 11:15 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Wed, 25 Mar 2026 08:24:40 +0700
John Naylor <johncnaylorls@gmail.com> wrote:

I'm ambivalent about this. Instead of trying to document all the
possible valid possibilities (which may get out of date again), maybe
we can say that it's not allowed on a single column?

Thank you for the suggestion. I agree that this is a simpler approach,
so I've attached a revised patch.

- errmsg("extended statistics require at least 2 columns")));
+ errmsg("extended statistics are not supported on a single column")));

I'd probably write this as "extended statistics on a single column are
not supported" (no need to send a new patch).

Any objections?

Also, I'm leaning towards not backpatching -- I figure a user that got
here by fat-fingering an expression is not likely to be too confused.

I looked in the feature thread and saw that this was actually raised
during development of the feature:

/messages/by-id/CAEZATCU9uPo7JYdx4k0-ufXXZH8t7itodibUwCva+s+AvAKcnw@mail.gmail.com

--
John Naylor
Amazon Web Services

#5Yugo Nagata
nagata@sraoss.co.jp
In reply to: John Naylor (#4)
Re: Adjust error message for CREATE STATISTICS to account for expressions

That sounds good to me.That sounds good to me.On Thu, 26 Mar 2026 16:22:07 +0700
John Naylor <johncnaylorls@gmail.com> wrote:

On Wed, Mar 25, 2026 at 11:15 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Wed, 25 Mar 2026 08:24:40 +0700
John Naylor <johncnaylorls@gmail.com> wrote:

I'm ambivalent about this. Instead of trying to document all the
possible valid possibilities (which may get out of date again), maybe
we can say that it's not allowed on a single column?

Thank you for the suggestion. I agree that this is a simpler approach,
so I've attached a revised patch.

- errmsg("extended statistics require at least 2 columns")));
+ errmsg("extended statistics are not supported on a single column")));

I'd probably write this as "extended statistics on a single column are
not supported" (no need to send a new patch).

Any objections?

That sounds good to me.

Also, I'm leaning towards not backpatching -- I figure a user that got
here by fat-fingering an expression is not likely to be too confused.

+1

Regards,
Yugo Nagata

I looked in the feature thread and saw that this was actually raised
during development of the feature:

/messages/by-id/CAEZATCU9uPo7JYdx4k0-ufXXZH8t7itodibUwCva+s+AvAKcnw@mail.gmail.com

--
John Naylor
Amazon Web Services

--
Yugo Nagata <nagata@sraoss.co.jp>

#6Michael Paquier
michael@paquier.xyz
In reply to: John Naylor (#4)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Thu, Mar 26, 2026 at 04:22:07PM +0700, John Naylor wrote:

I'd probably write this as "extended statistics on a single column are
not supported" (no need to send a new patch).

Any objections?

None. I have found this error message puzzling while doing some of my
recent work for extended statistics, because extended statistics can
be created if there is a single element made of an expression in the
list given in input.

Also, I'm leaning towards not backpatching -- I figure a user that got
here by fat-fingering an expression is not likely to be too confused.

-    errmsg("extended statistics require at least 2 columns")));
+    errmsg("extended statistics are not supported on a single column")));

Now our documentation also tells that the former message is not the
preferred project style (full sentences usually avoided in primary
messages):
https://www.postgresql.org/docs/devel/error-style-guide.html#ERROR-STYLE-GUIDE-GRAMMAR-PUNCTUATION

Perhaps something like "could not create extended statistics" with a
hint describing the cause would be better.. Full sentences usually
apply to errdetails or errhints. If we're on it, we could just as
well improve the whole thing, I guess?
--
Michael

#7John Naylor
john.naylor@enterprisedb.com
In reply to: Michael Paquier (#6)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Fri, Mar 27, 2026 at 6:23 AM Michael Paquier <michael@paquier.xyz> wrote:

-    errmsg("extended statistics require at least 2 columns")));
+    errmsg("extended statistics are not supported on a single column")));

Now our documentation also tells that the former message is not the
preferred project style (full sentences usually avoided in primary
messages):
https://www.postgresql.org/docs/devel/error-style-guide.html#ERROR-STYLE-GUIDE-GRAMMAR-PUNCTUATION

My reading of that is that hints/details need to be complete
sentences, and primary messages don't need to be. If the obvious way
to write primary message is with a complete sentence, I would say
that's fine, but I don't have a lot of context here.

Perhaps something like "could not create extended statistics" with a
hint describing the cause would be better.. Full sentences usually
apply to errdetails or errhints. If we're on it, we could just as
well improve the whole thing, I guess?

I don't feel strongly either way, so in that case I would default to
not changing to errdetail. Looking elsewhere in this file, however, I
do see some messages with "cannot do X because ....", and I'd be more
motivated to turn those "because" phrases into errdetails.

--
John Naylor
Amazon Web Services

#8Yugo Nagata
nagata@sraoss.co.jp
In reply to: John Naylor (#7)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Fri, 27 Mar 2026 07:45:37 +0700
John Naylor <johncnaylorls@gmail.com> wrote:

On Fri, Mar 27, 2026 at 6:23 AM Michael Paquier <michael@paquier.xyz> wrote:

-    errmsg("extended statistics require at least 2 columns")));
+    errmsg("extended statistics are not supported on a single column")));

Now our documentation also tells that the former message is not the
preferred project style (full sentences usually avoided in primary
messages):
https://www.postgresql.org/docs/devel/error-style-guide.html#ERROR-STYLE-GUIDE-GRAMMAR-PUNCTUATION

My reading of that is that hints/details need to be complete
sentences, and primary messages don't need to be. If the obvious way
to write primary message is with a complete sentence, I would say
that's fine, but I don't have a lot of context here.

Perhaps something like "could not create extended statistics" with a
hint describing the cause would be better.. Full sentences usually
apply to errdetails or errhints. If we're on it, we could just as
well improve the whole thing, I guess?

I don't feel strongly either way, so in that case I would default to
not changing to errdetail. Looking elsewhere in this file, however, I
do see some messages with "cannot do X because ....", and I'd be more
motivated to turn those "because" phrases into errdetails.

I don't have a strong preference here, so I'm fine with either approach.
I also agree that moving "because ..." into errdetails in some longer
messages makes sense.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

#9Dean Rasheed
dean.a.rasheed@gmail.com
In reply to: Yugo Nagata (#8)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Fri, 27 Mar 2026 at 04:46, Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Fri, 27 Mar 2026 07:45:37 +0700
John Naylor <johncnaylorls@gmail.com> wrote:

On Fri, Mar 27, 2026 at 6:23 AM Michael Paquier <michael@paquier.xyz> wrote:

-    errmsg("extended statistics require at least 2 columns")));
+    errmsg("extended statistics are not supported on a single column")));

Now our documentation also tells that the former message is not the
preferred project style (full sentences usually avoided in primary
messages):
https://www.postgresql.org/docs/devel/error-style-guide.html#ERROR-STYLE-GUIDE-GRAMMAR-PUNCTUATION

My reading of that is that hints/details need to be complete
sentences, and primary messages don't need to be. If the obvious way
to write primary message is with a complete sentence, I would say
that's fine, but I don't have a lot of context here.

Perhaps something like "could not create extended statistics" with a
hint describing the cause would be better.. Full sentences usually
apply to errdetails or errhints. If we're on it, we could just as
well improve the whole thing, I guess?

I don't feel strongly either way, so in that case I would default to
not changing to errdetail. Looking elsewhere in this file, however, I
do see some messages with "cannot do X because ....", and I'd be more
motivated to turn those "because" phrases into errdetails.

I don't have a strong preference here, so I'm fine with either approach.
I also agree that moving "because ..." into errdetails in some longer
messages makes sense.

I don't think it should be a hint, because that's more for suggestions
on how to fix the problem.

Given that the user just tried to create extended statistics on a
single column, they're probably not interested in expression
statistics or multivariate statistics, so a single short "not
supported" error seems sufficient.

If we were to give more detail, it should probably be to point out
that regular statistics will already be built for single columns,
which is why single-column extended statistics would be redundant. So
perhaps something like this:

Error: cannot create extended statistics on a single column
Detail: Univariate statistics are already built for each individual
table column.

Regards,
Dean

#10Yugo Nagata
nagata@sraoss.co.jp
In reply to: Dean Rasheed (#9)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Fri, 27 Mar 2026 09:50:07 +0000
Dean Rasheed <dean.a.rasheed@gmail.com> wrote:

On Fri, 27 Mar 2026 at 04:46, Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Fri, 27 Mar 2026 07:45:37 +0700
John Naylor <johncnaylorls@gmail.com> wrote:

On Fri, Mar 27, 2026 at 6:23 AM Michael Paquier <michael@paquier.xyz> wrote:

-    errmsg("extended statistics require at least 2 columns")));
+    errmsg("extended statistics are not supported on a single column")));

Now our documentation also tells that the former message is not the
preferred project style (full sentences usually avoided in primary
messages):
https://www.postgresql.org/docs/devel/error-style-guide.html#ERROR-STYLE-GUIDE-GRAMMAR-PUNCTUATION

My reading of that is that hints/details need to be complete
sentences, and primary messages don't need to be. If the obvious way
to write primary message is with a complete sentence, I would say
that's fine, but I don't have a lot of context here.

Perhaps something like "could not create extended statistics" with a
hint describing the cause would be better.. Full sentences usually
apply to errdetails or errhints. If we're on it, we could just as
well improve the whole thing, I guess?

I don't feel strongly either way, so in that case I would default to
not changing to errdetail. Looking elsewhere in this file, however, I
do see some messages with "cannot do X because ....", and I'd be more
motivated to turn those "because" phrases into errdetails.

I don't have a strong preference here, so I'm fine with either approach.
I also agree that moving "because ..." into errdetails in some longer
messages makes sense.

I don't think it should be a hint, because that's more for suggestions
on how to fix the problem.

Given that the user just tried to create extended statistics on a
single column, they're probably not interested in expression
statistics or multivariate statistics, so a single short "not
supported" error seems sufficient.

If we were to give more detail, it should probably be to point out
that regular statistics will already be built for single columns,
which is why single-column extended statistics would be redundant. So
perhaps something like this:

Error: cannot create extended statistics on a single column
Detail: Univariate statistics are already built for each individual
table column.

That makes sense to me.

Using an errdetail to explain the reason sounds reasonable.

--
Yugo Nagata <nagata@sraoss.co.jp>

#11Chao Li
li.evan.chao@gmail.com
In reply to: John Naylor (#7)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Mar 27, 2026, at 08:45, John Naylor <johncnaylorls@gmail.com> wrote:

On Fri, Mar 27, 2026 at 6:23 AM Michael Paquier <michael@paquier.xyz> wrote:

-    errmsg("extended statistics require at least 2 columns")));
+    errmsg("extended statistics are not supported on a single column")));

Now our documentation also tells that the former message is not the
preferred project style (full sentences usually avoided in primary
messages):
https://www.postgresql.org/docs/devel/error-style-guide.html#ERROR-STYLE-GUIDE-GRAMMAR-PUNCTUATION

My reading of that is that hints/details need to be complete
sentences, and primary messages don't need to be.

+1

From: Dean Rasheed <dean.a.rasheed@gmail.com>

If we were to give more detail, it should probably be to point out
that regular statistics will already be built for single columns,
which is why single-column extended statistics would be redundant. So
perhaps something like this:

Error: cannot create extended statistics on a single column
Detail: Univariate statistics are already built for each individual
table column.

I like this version.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

#12John Naylor
john.naylor@enterprisedb.com
In reply to: Yugo Nagata (#10)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Sat, Mar 28, 2026 at 1:04 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Fri, 27 Mar 2026 09:50:07 +0000
Dean Rasheed <dean.a.rasheed@gmail.com> wrote:

If we were to give more detail, it should probably be to point out
that regular statistics will already be built for single columns,
which is why single-column extended statistics would be redundant. So
perhaps something like this:

Error: cannot create extended statistics on a single column
Detail: Univariate statistics are already built for each individual
table column.

That makes sense to me.

Using an errdetail to explain the reason sounds reasonable.

Works for me.

On Fri, 27 Mar 2026 07:45:37 +0700
John Naylor <johncnaylorls@gmail.com> wrote:

Looking elsewhere in this file, however, I
do see some messages with "cannot do X because ....", and I'd be more
motivated to turn those "because" phrases into errdetails.

Did you also want to try tackling this while we're here?

--
John Naylor
Amazon Web Services

#13Yugo Nagata
nagata@sraoss.co.jp
In reply to: John Naylor (#12)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Mon, 30 Mar 2026 10:21:54 +0700
John Naylor <johncnaylorls@gmail.com> wrote:

On Sat, Mar 28, 2026 at 1:04 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Fri, 27 Mar 2026 09:50:07 +0000
Dean Rasheed <dean.a.rasheed@gmail.com> wrote:

If we were to give more detail, it should probably be to point out
that regular statistics will already be built for single columns,
which is why single-column extended statistics would be redundant. So
perhaps something like this:

Error: cannot create extended statistics on a single column
Detail: Univariate statistics are already built for each individual
table column.

That makes sense to me.

Using an errdetail to explain the reason sounds reasonable.

Works for me.

On Fri, 27 Mar 2026 07:45:37 +0700
John Naylor <johncnaylorls@gmail.com> wrote:

Looking elsewhere in this file, however, I
do see some messages with "cannot do X because ....", and I'd be more
motivated to turn those "because" phrases into errdetails.

Did you also want to try tackling this while we're here?

Yes, that sounds good to me.

In particular, the following suggestion from Dean Rasheed seems like a
good approach:

Error: cannot create extended statistics on a single column
Detail: Univariate statistics are already built for each individual
table column

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

#14Dean Rasheed
dean.a.rasheed@gmail.com
In reply to: Yugo Nagata (#13)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Tue, 31 Mar 2026 at 15:47, Yugo Nagata <nagata@sraoss.co.jp> wrote:

Yes, that sounds good to me.

In particular, the following suggestion from Dean Rasheed seems like a
good approach:

Error: cannot create extended statistics on a single column
Detail: Univariate statistics are already built for each individual
table column

I've pushed that change as part of the patch to support extended
statistics on virtual generated columns [1]/messages/by-id/20250422181006.dd6f9d1d81299f5b2ad55e1a@sraoss.co.jp, since I felt that patch
already needed to change that error message.

I didn't look more widely at other error messages in that file might
benefit from having separate errdetail text.

Regards,
Dean

[1]: /messages/by-id/20250422181006.dd6f9d1d81299f5b2ad55e1a@sraoss.co.jp

#15Yugo Nagata
nagata@sraoss.co.jp
In reply to: Dean Rasheed (#14)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Wed, 1 Apr 2026 17:19:16 +0100
Dean Rasheed <dean.a.rasheed@gmail.com> wrote:

On Tue, 31 Mar 2026 at 15:47, Yugo Nagata <nagata@sraoss.co.jp> wrote:

Yes, that sounds good to me.

In particular, the following suggestion from Dean Rasheed seems like a
good approach:

Error: cannot create extended statistics on a single column
Detail: Univariate statistics are already built for each individual
table column

I've pushed that change as part of the patch to support extended
statistics on virtual generated columns [1], since I felt that patch
already needed to change that error message.

Thank you for handling this.

I didn't look more widely at other error messages in that file might
benefit from having separate errdetail text.

I’ve attached a patch that also updates other error messages to move
their reason parts into errdetail.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

Attachments:

v3-Adjust_error_message_for_CREATE_STATISTICS.patchtext/x-diff; name=v3-Adjust_error_message_for_CREATE_STATISTICS.patchDownload+13-7
#16John Naylor
john.naylor@enterprisedb.com
In reply to: Yugo Nagata (#15)
Re: Adjust error message for CREATE STATISTICS to account for expressions

On Fri, Apr 3, 2026 at 8:44 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

I’ve attached a patch that also updates other error messages to move
their reason parts into errdetail.

Pushed, thanks!

--
John Naylor
Amazon Web Services