Re: Make SPI_prepare argtypes argument const

Ewan Young <kdbase.hack@gmail.com>

From: Ewan Young <kdbase.hack@gmail.com>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-06-11T09:59:55Z
Lists: pgsql-hackers
Reviewed this. LGTM.

I checked that argtypes / param_types is only ever read or copied along
this path (never written or freed through the pointer), so const-qualifying
it is sound rather than merely tolerated. In particular CompleteCachedPlan()
palloc's its own copy and never retains the caller's array. pg_analyze_and_
rewrite_fixedparams() already takes const Oid *, so no further change is
needed there.

Applies cleanly on HEAD and builds without warnings here.

On Thu, Jun 11, 2026 at 5:22 PM Peter Eisentraut <peter@eisentraut.org> wrote:
>
> This changes the argtypes argument of SPI_prepare(),
> SPI_prepare_cursor(), SPI_cursor_open_with_args(), and
> SPI_execute_with_args() from Oid *argtypes to const Oid *argtypes.
> The underlying functions were already receptive to that, so this
> doesn't require any significant changes beyond the function signatures
> and some internal variables.
>
> Commit 28972b6fc3dc recently introduced a case where a const had to be
> cast away before calling these functions.  This is fixed here.



Commits

  1. Make SPI_prepare argtypes argument const

  2. Fixes for SPI "const Datum *" use

  3. Add support for importing statistics from remote servers.