From: | David Fetter <david(at)fetter(dot)org> |
---|---|
To: | a_ogawa <a_ogawa(at)hi-ho(dot)ne(dot)jp> |
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 00:59:12 |
Message-ID: | 20050607005912.GB5196@fetter.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-patches |
On Tue, Jun 07, 2005 at 09:35:56AM +0900, a_ogawa wrote:
>
> Bruce Momjian wrote:
> > David Fetter wrote:
> > > On Mon, Jun 06, 2005 at 12:02:18PM -0400, Bruce Momjian wrote:
> > > >
> > > > Patch removed because we already have this functionality.
> > >
> > > 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 :)
> >
> > Does anyone want to argue that this additional functionality is
> > significant and deserves its own function or an additional
> > argument to the existing function?
>
> Oracle10g has a similar functionality. The name is regexp_replace.
> There is the following usages in this functionality.
> - Format the ZIP code and the telephone number, etc.
> Example: select regexp_replace('1112223333', '(\\d{3})(\\d{3})(\\d{4})',
> '(\\1) \\2-\\3');
> result: (111) 222-3333
> - Delete an unnecessary white space.
> Example: select regexp_replace('A B C', '\\s+', ' ');
> result: A B C
>
> 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?
Cheers,
D
--
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778
Remember to vote!
From | Date | Subject | |
---|---|---|---|
Next Message | John Hansen | 2005-06-07 01:00:41 | Re: unicode upper/lower functions |
Previous Message | Alvaro Herrera | 2005-06-07 00:42:30 | Re: adding new pages bulky way |
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2005-06-07 01:23:21 | Re: libpq API incompatibility between 7.4 and 8.0 |
Previous Message | a_ogawa | 2005-06-07 00:35:56 | Re: [HACKERS] regexp_replace |