Re: [HACKERS] regexp_replace

From: Atsushi Ogawa <a_ogawa(at)hi-ho(dot)ne(dot)jp>
To: David Fetter <david(at)fetter(dot)org>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-patches(at)postgresql(dot)org, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] regexp_replace
Date: 2005-06-07 13:27:28
Message-ID: PIEMIKOOMKNIJLLLBCBBGEAGCIAA.a_ogawa@hi-ho.ne.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches


David Fetter wrote:
> On Tue, Jun 07, 2005 at 09:35:56AM +0900, a_ogawa wrote:
> > David Fetter wrote:
> > > We don't yet have this functionality, as the patch allows for
> > > using second and later regex matches "()" in the replacement
> > > pattern.
> > >
> > > The function is misnamed. It should be called
> > > regex_replace_all() or some such, as it violates the principle
> > > of least astonishment by replacing all instances by default.
> > > Every other regex replacement defaults to "replace first," not
> > > "replace all." Or maybe it should take a bool for "replace
> > > all," or...? Anyhow, it's worth a discussion :)
> >
> > I think that the usage increases if "replace all" or "replace first" can
be
> > specified to this function.
>
> Ogawa-san,
>
> I think that this would be a case for function overloading:
>
> function regexp_replace(
> string text, pattern text, replacement text
> ) RETURNS TEXT; /* First only */
>
> regexp_replace(
> string text, pattern text, replacement text, global bool
> ) RETURNS TEXT; /* Global if global is TRUE, first only otherwise */
>
> What do you think of this idea? One trouble is that there are some
> other options. For example, one could add switches for all
> combinations of "global," "case insensitive," "compile once," "exclude
> whitespace," etc. as perl does. Do we want to go this route?

My idea is opposite. I think that the regexp_replace() should make
"replace all" a default. Because the replace() of pgsql replaces all
string, and regexp_replace() of oracle10g is also similar.

And I think that it is better to be able to specify the option with text.
I think about this function specification:

regexp_replace(
string text, pattern text, replacement text
) RETURNS TEXT; /* Replace all */

regexp_replace(
string text, pattern text, replacement text, options text
) RETURNS TEXT; /* Change operation by the option. */

The options can use the following values.
f: Replace first only
i: Case insensitive

Any comments?

regards,

---
Atsushi Ogawa

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Oleg Bartunov 2005-06-07 13:47:25 GiST concurrency and recovery for 8.1
Previous Message Phil Endecott 2005-06-07 11:16:19 Re: CPU-intensive autovacuuming

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2005-06-07 14:34:14 Re: uptime function to postmaster
Previous Message Andreas Pflug 2005-06-07 11:50:53 Re: Server instrumentation: pg_terminate_backend, pg_reload_conf