regular expression substittion function?

Started by Bruno Wolff IIIabout 25 years ago10 messagesgeneral
Jump to latest
#1Bruno Wolff III
bruno@wolff.to

Are there any plans to provide a regular expression substitution function,
similar to translate but allowing more complex substitutions?

This is an example of what I want to use it for. I am using a query that
builds web urls from a couple of different types of data and then union
together. Some of the data is raw urls, and some is title information
that gets turn into search urls. The title information needs to be
massaged before being used in a url and it needs to be done in the query
if I want to do the union. The translate command could be used in my
particular case, but it will be very long, as I need to delete most
nonletter nondigit characters and change spaces to plusses. A regular
expression describing what I want would be much more compact.

#2Bruce Momjian
bruce@momjian.us
In reply to: Bruno Wolff III (#1)
Re: regular expression substittion function?

I thought someone suggested that, but I can't remember what happened to
it. We have a Perl internal language that works in 7.1beta. You
basically want a sed-type ability. I can see real value in that.

Are there any plans to provide a regular expression substitution function,
similar to translate but allowing more complex substitutions?

This is an example of what I want to use it for. I am using a query that
builds web urls from a couple of different types of data and then union
together. Some of the data is raw urls, and some is title information
that gets turn into search urls. The title information needs to be
massaged before being used in a url and it needs to be done in the query
if I want to do the union. The translate command could be used in my
particular case, but it will be very long, as I need to delete most
nonletter nondigit characters and change spaces to plusses. A regular
expression describing what I want would be much more compact.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#3Bruce Momjian
bruce@momjian.us
In reply to: Bruno Wolff III (#1)
Re: regular expression substittion function?

Added to TODO:

* Add sed-like regular expression search/replace capability

Are there any plans to provide a regular expression substitution function,
similar to translate but allowing more complex substitutions?

This is an example of what I want to use it for. I am using a query that
builds web urls from a couple of different types of data and then union
together. Some of the data is raw urls, and some is title information
that gets turn into search urls. The title information needs to be
massaged before being used in a url and it needs to be done in the query
if I want to do the union. The translate command could be used in my
particular case, but it will be very long, as I need to delete most
nonletter nondigit characters and change spaces to plusses. A regular
expression describing what I want would be much more compact.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#4David E. Wheeler
david@kineticode.com
In reply to: Bruce Momjian (#2)
Re: regular expression substittion function?

On Thu, 15 Feb 2001, Bruce Momjian wrote:

I thought someone suggested that, but I can't remember what happened to
it. We have a Perl internal language that works in 7.1beta. You
basically want a sed-type ability. I can see real value in that.

A "Perl internal language" in 7.1? Can you tell me what that means? Is it
like Oracle's feature allowing one to write SPs in Java? I can tell you
right now that the ability to write SPs in Perl would *totally* rock, from
my point of view.

Thanks!

David

#5Bruce Momjian
bruce@momjian.us
In reply to: David E. Wheeler (#4)
Re: regular expression substittion function?

On Thu, 15 Feb 2001, Bruce Momjian wrote:

I thought someone suggested that, but I can't remember what happened to
it. We have a Perl internal language that works in 7.1beta. You
basically want a sed-type ability. I can see real value in that.

A "Perl internal language" in 7.1? Can you tell me what that means? Is it
like Oracle's feature allowing one to write SPs in Java? I can tell you
right now that the ability to write SPs in Perl would *totally* rock, from
my point of view.

Yes, SP's in Perl, Tcl, or PL/SQL-type languages. Perl only works well in
7.1beta.

What do people think of this TODO item:

* Add sed-like regular expression search/replace capability

Seems it would be nice for quick and dirty stuff rather than having to
define a function.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#6David E. Wheeler
david@kineticode.com
In reply to: Bruce Momjian (#5)
Re: regular expression substittion function?

On Thu, 15 Feb 2001, Bruce Momjian wrote:

Yes, SP's in Perl, Tcl, or PL/SQL-type languages. Perl only works well in
7.1beta.

Very cool! We have to compile --with-perl, yes? Where may I find
documentation on how to use it?

What do people think of this TODO item:

* Add sed-like regular expression search/replace capability

Seems it would be nice for quick and dirty stuff rather than having to
define a function.

Yeah, I think that's a nice idea.

Thanks,

David

#7Bruce Momjian
bruce@momjian.us
In reply to: David E. Wheeler (#6)
Re: regular expression substittion function?

On Thu, 15 Feb 2001, Bruce Momjian wrote:

Yes, SP's in Perl, Tcl, or PL/SQL-type languages. Perl only works well in
7.1beta.

Very cool! We have to compile --with-perl, yes? Where may I find
documentation on how to use it?

I think so. You have to install the perl language in your database with
createlang. Not sure about the steps or docs.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#8Bruno Wolff III
bruno@wolff.to
In reply to: Bruce Momjian (#2)
Re: regular expression substittion function?

On Thu, Feb 15, 2001 at 11:01:18AM -0500,
Bruce Momjian <pgman@candle.pha.pa.us> wrote:

I thought someone suggested that, but I can't remember what happened to
it. We have a Perl internal language that works in 7.1beta. You
basically want a sed-type ability. I can see real value in that.

I am running 7.1beta3. I will take a look at that and see what I can
figure out. I am still pretty much a beginner. I am doing OK with SQL
but have only briefly looked at using the language stuff.

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#7)
Re: regular expression substittion function?

Very cool! We have to compile --with-perl, yes? Where may I find
documentation on how to use it?

I think so. You have to install the perl language in your database with
createlang. Not sure about the steps or docs.

http://www.postgresql.org/devel-corner/docs/postgres/plperl.htm

regards, tom lane

#10David E. Wheeler
david@kineticode.com
In reply to: Tom Lane (#9)
Re: regular expression substittion function?

On Thu, 15 Feb 2001, Tom Lane wrote:

Very cool! We have to compile --with-perl, yes? Where may I find
documentation on how to use it?

I think so. You have to install the perl language in your database with
createlang. Not sure about the steps or docs.

http://www.postgresql.org/devel-corner/docs/postgres/plperl.htm

Way bitchen'! Thanks, Tom!

Best,

David