Re: generating function default settings from pg_proc.dat

From: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generating function default settings from pg_proc.dat
Date: 2026-02-16 18:08:22
Message-ID: CADkLM=dZa86W+cOb8RsghFHCL8-SbcCFpwusEZctt1mYN36uzA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Feb 16, 2026 at 12:31 PM Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:

>
> Motivated by Bug 19409 [1] I decided to do something about a wart that
> has bugged me for a while, namely the requirement to write stuff in
> system_views.sql if you need to specify default values for function
> arguments. Here's my attempt. The first patch here sets up the required
> infrastructure. genbki.pl creates a file called function_defaults.sql
> which is run by initdb at the appropriate time. There are two new fields
> in pg_proc.dat entries: proargdflts,and provariadicdflt. These are
> parsed and the appropriate CREATE OR REPLACE statement is generated and
> placed in function_defaults.sql. The second patch applies this treatment
> to 37 function definitions and removes the corresponding statements from
> system_views.sql. This gets us closer to having pg_proc.dat as a single
> source of truth.

+1 for the attempt. My preference would be for allowing CREATE OR REPLACE
to specify an oid, but that's a non-starter for bootstrapping purposes, so
this is the next best option.

The defaults read a little funny in that a human reader must line up the
defaults right-to-left to then determine a given parameter's default, if
any. For example:

proname => 'json_strip_nulls', prorettype => 'json',
- proargtypes => 'json bool', prosrc => 'json_strip_nulls' },
+ proargtypes => 'json bool',
+ proargnames => '{target,strip_in_arrays}', proargdflts => '{false}',
+ prosrc => 'json_strip_nulls' },

Perhaps we could require proargdflts to pre-pad with empty values

proargdflts => '{,false}'

or even be a hash

proargdflts => { strip_in_arrays => 'false' }

which I will grant you is wordy, but its definitely clearer.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-02-16 18:08:23 Re: generating function default settings from pg_proc.dat
Previous Message Daniel Gustafsson 2026-02-16 18:07:34 Re: generating function default settings from pg_proc.dat