Re: Add expressions to pg_restore_extended_stats()

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Corey Huinker <corey.huinker@gmail.com>
Cc: Chao Li <li.evan.chao@gmail.com>, Tender Wang <tndrwang@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Tomas Vondra <tomas@vondra.me>
Date: 2026-02-04T05:56:39Z
Lists: pgsql-hackers
On Wed, Feb 04, 2026 at 12:14:06AM -0500, Corey Huinker wrote:
> I'll switch to adding the nulls to the array result, and add tests for both
> leading and trailing expr missing.

OK, fine by me.  Thanks.  Let's make something happen to finish all
that.

> Mild change of subject, it seems that we can't get the expression fake
> attnum context into the errors we re-throw in statatt_build_stavalues - it
> might make sense to to bring a version of that function into
> extended_stats_funcs where we can add the extra parameters for context (and
> avoid the need for a text datum version of some longish strings that we've
> already just converted from converting json-string to c-string. If I did
> make a new function, then that'd be 2 statatt_* functions that no longer
> need to be visible outside of attribute_stats.c. Thoughts on both making
> the new function, and maybe sending a few of these statatts back to
> static-land?

Hmm.  I am not sure, that depends.  How much additional information
would these extra parameter bring to the errors generated in
statatt_build_stavalues().  We could also set an error context
callback (ErrorContextCallback) within import_pg_statistic() or in the
loop that calls the routine, with some data based on the counter of
"numexprs" to provide more context about where an error is happening.
I have used that in the past to avoid complicating functions across
multiple levels of a stack (for example, see ReindexPartitions() in
indexcmds.c with its ReindexErrorInfo).
--
Michael

Commits

  1. Refactor tests for catalog diff comparisons in stats_import.sql

  2. Fix typo in stats_import.sql

  3. Add support for "exprs" in pg_restore_extended_stats()

  4. Add information about range type stats to pg_stats_ext_exprs

  5. Fix comment in extended_stats_funcs.c