Unix Technical Forum

Re: [PATCHES] regexp_replace

This is a discussion on Re: [PATCHES] regexp_replace within the pgsql Hackers forums, part of the PostgreSQL category; --> David Fetter wrote: > On Tue, Jun 07, 2005 at 10:27:28PM +0900, Atsushi Ogawa wrote: > > David Fetter ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 05:15 AM
Atsushi Ogawa
 
Posts: n/a
Default Re: [PATCHES] regexp_replace


David Fetter wrote:
> On Tue, Jun 07, 2005 at 10:27:28PM +0900, Atsushi Ogawa wrote:
> > David Fetter wrote:
> > > 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.

>
> I respectfully disagree. Although Oracle does things this way, no
> other regular expression search and replace does. Historically, you
> can find that "Oracle does it this way" is not a reason why we would
> do it. Text editors, programming languages, etc., etc. do "replace
> the first" by default and "replace globally" only when told to.


I agree. Let's stop the way to Oracle.

> > And I think that it is better to be able to specify the option with

text.
>
> I think that "case insensitive" is a good thing to add separately as a
> boolean


I don't like to specify operation with boolean.
Because when a SQL is read, the meaning becomes indistinct.

How about changing the function name of each usage?

regexp_replace: replace first
regexp_replace_all: replace all
regexp_ic_replace: replace first and case insensitive
regexp_ic_replace_all: replace all and case insensitive

regards,

--
Atsushi Ogawa


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 05:16 AM
Hannu Krosing
 
Posts: n/a
Default Re: [PATCHES] regexp_replace

On K, 2005-06-08 at 21:32 +0900, Atsushi Ogawa wrote:

>
> How about changing the function name of each usage?
>
> regexp_replace: replace first
> regexp_replace_all: replace all
> regexp_ic_replace: replace first and case insensitive
> regexp_ic_replace_all: replace all and case insensitive


perhaps just "regexp_ireplace", we already have ILIKE not IC_LIKE


--
Hannu Krosing <hannu@skype.net>


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 05:16 AM
Andrew Dunstan
 
Posts: n/a
Default Re: [PATCHES] regexp_replace

Atsushi Ogawa said:
>
> How about changing the function name of each usage?
>
> regexp_replace: replace first
> regexp_replace_all: replace all
> regexp_ic_replace: replace first and case insensitive
> regexp_ic_replace_all: replace all and case insensitive
>



That's just horrible. The number of function names will double with each
supported flag (e.g. I'd like to see extended regexes supported).

surely somthing like

foo_replace (source text, pattern text, replacement text, flags text)
returns text

would fit the bill. OK, it reflects my Perl prejudices, but that looks more
natural to me. You could overload it so that the flags default to none
(which would be case sensitive, replace the first instance only, among other
things).

cheers

andrew



---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 05:16 AM
Bruce Momjian
 
Posts: n/a
Default Re: [PATCHES] regexp_replace

Andrew Dunstan wrote:
> Atsushi Ogawa said:
> >
> > How about changing the function name of each usage?
> >
> > regexp_replace: replace first
> > regexp_replace_all: replace all
> > regexp_ic_replace: replace first and case insensitive
> > regexp_ic_replace_all: replace all and case insensitive
> >

>
>
> That's just horrible. The number of function names will double with each
> supported flag (e.g. I'd like to see extended regexes supported).
>
> surely somthing like
>
> foo_replace (source text, pattern text, replacement text, flags text)
> returns text
>
> would fit the bill. OK, it reflects my Perl prejudices, but that looks more
> natural to me. You could overload it so that the flags default to none
> (which would be case sensitive, replace the first instance only, among other
> things).


Can we have the flags be a list of words, e.g. "all, ignorecase". How
do we handle this type of problem in other cases?

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-11-2008, 05:16 AM
Tom Flavel
 
Posts: n/a
Default Re: [PATCHES] regexp_replace

On 08/06/2005 21:57:29, Bruce Momjian wrote:
> Andrew Dunstan wrote:
> > Atsushi Ogawa said:
> > >
> > > How about changing the function name of each usage?
> > >
> > > regexp_replace: replace first
> > > regexp_replace_all: replace all
> > > regexp_ic_replace: replace first and case insensitive
> > > regexp_ic_replace_all: replace all and case insensitive

> >
> >
> > That's just horrible. The number of function names will double with each
> > supported flag (e.g. I'd like to see extended regexes supported).
> >
> > surely somthing like
> >
> > foo_replace (source text, pattern text, replacement text, flags text)
> > returns text
> >
> > would fit the bill. OK, it reflects my Perl prejudices, but that looks more
> > natural to me. You could overload it so that the flags default to none
> > (which would be case sensitive, replace the first instance only, among other
> > things).

>
> Can we have the flags be a list of words, e.g. "all, ignorecase". How
> do we handle this type of problem in other cases?


How about an array?

Cumbersome, perhaps, but it makes more sense to me than delimiting with
commas or using single characters.

--
Tom

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-11-2008, 05:17 AM
Atsushi Ogawa
 
Posts: n/a
Default Re: [PATCHES] regexp_replace


Tom Flavel wrote:
> On 08/06/2005 21:57:29, Bruce Momjian wrote:
> > Andrew Dunstan wrote:
> > >
> > > surely somthing like
> > >
> > > foo_replace (source text, pattern text, replacement text, flags

text)
> > > returns text
> > >
> > > would fit the bill. OK, it reflects my Perl prejudices, but that
> > > looks more natural to me. You could overload it so that the flags
> > > default to none
> > > (which would be case sensitive, replace the first instance only,
> > > among other things).

> >
> > Can we have the flags be a list of words, e.g. "all, ignorecase". How
> > do we handle this type of problem in other cases?

>
> How about an array?
>
> Cumbersome, perhaps, but it makes more sense to me than delimiting with
> commas or using single characters.


I think that it is good to specify the flags by one character as well
as Perl.

I propose the following specification:

regexp_replace(source text, pattern text, replacement text, [flags text])
returns text

The flags can use the following values:
g: global (replace all)
i: ignore case

When the flags is not specified, case sensitive, replace the first
instance only.

regards,

---
Atsushi Ogawa


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-11-2008, 05:34 AM
Bruce Momjian
 
Posts: n/a
Default Re: [PATCHES] regexp_replace

Atsushi Ogawa wrote:
> I think that it is good to specify the flags by one character as well
> as Perl.
>
> I propose the following specification:
>
> regexp_replace(source text, pattern text, replacement text, [flags text])
> returns text
>
> The flags can use the following values:
> g: global (replace all)
> i: ignore case
>
> When the flags is not specified, case sensitive, replace the first
> instance only.


This seems good to me.

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-11-2008, 05:34 AM
Atsushi Ogawa
 
Posts: n/a
Default Re: [PATCHES] regexp_replace


Bruce Momjian wrote:
> Atsushi Ogawa wrote:
> > I propose the following specification:
> >
> > regexp_replace(source text, pattern text, replacement text, [flags

text])
> > returns text
> >
> > The flags can use the following values:
> > g: global (replace all)
> > i: ignore case
> >
> > When the flags is not specified, case sensitive, replace the first
> > instance only.

>
> This seems good to me.


Thanks. I will remake the patch within a few days.

regards,

--- Atsushi Ogawa


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:33 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com