Re: add function argument names to regex* functions. - Mailing list pgsql-hackers

From jian he
Subject Re: add function argument names to regex* functions.
Date
Msg-id CACJufxE5p4KhGyBUwCZCxhxdU+zJBXy2deX4u85SL+kew4F7Cw@mail.gmail.com
Whole thread Raw
In response to Re: add function argument names to regex* functions.  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: add function argument names to regex* functions.
List pgsql-hackers
On Fri, Jul 19, 2024 at 5:48 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> jian he <jian.universality@gmail.com> writes:
> > [ v5-0001-add-regex-functions-argument-names-to-pg_proc.patch ]
>
> I'm not sure whether we've bikeshedded this to death yet, but
> personally I'm content with the naming choices here (which basically
> are those already shown in table 9.10).  However, while looking
> at the patch I noticed a couple of issues, one small, the other
> a bit bigger.
>
> The small issue is that table 9.10 offers this syntax diagram
> for regexp_replace:
>
> regexp_replace ( string text, pattern text, replacement text [, start integer ] [, flags text ] ) → text
>
> This implies that it's valid to write
>
>         regexp_replace (string, pattern, replacement, start, flags)
>
> but it is not: we have no function matching that signature.  I'm not
> in a hurry to add one, either, for fear of ambiguity against the other
> regexp_replace signature.  I think this needs to be broken into two
> syntax diagrams:
>
> regexp_replace ( string text, pattern text, replacement text [, start integer ] ) → text
> regexp_replace ( string text, pattern text, replacement text [, flags text ] ) → text


We can list  them separately.
regexp_replace(string, pattern, replacement [, start])
regexp_replace(string, pattern, replacement [, flags])
regexp_replace(string, pattern, replacement , start , N [, flags ]).

if both optional is not there then they are the same, list 2 potential
identical functions separately seems wrong?
so i choose 2 bracket with a vertical bar:

regexp_replace(string, pattern, replacement [[, start] | [, flags]]).

maybe less readable.


> The larger issue is that contrib/citext offers versions of some of
> these functions that are meant to be drop-in replacements using
> citext input.  Hence, we need to add the same parameter names to
> those functions, or they'll fail to replace some calls.
>

I first wanted to use alterfunction solve this, then found out it cannot,
later I found out CREATE OR REPLACE FUNCTION saved us.

citext module, these functions:
regexp_match()
regexp_matches()
regexp_replace()
regexp_split_to_array()
regexp_split_to_table()
were created in contrib/citext/citext--1.4.sql, we can add the CREATE
OR REPLACE FUNCTION to 1.4.sql.
but to avoid unintended consequences I just add these to the newly
created file citext--1.6--1.7.sql,
to make a version bump.

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Patch bug: Fix jsonpath .* on Arrays
Next
From: Shlok Kyal
Date:
Subject: Re: Pgoutput not capturing the generated columns