Re: perlsub - Mailing list pgsql-novice

From Jeff Eckermann
Subject Re: perlsub
Date
Msg-id 20031007194659.39415.qmail@web20801.mail.yahoo.com
Whole thread Raw
In response to Re: perlsub  (Nabil Sayegh <postgresql@e-trolley.de>)
Responses Re: perlsub
List pgsql-novice
jeff=# create or replace function s(text, text, text)
returns text as '$_[0] =~ s/$_[1]/$_[2]/ee; return
$_[0]' language 'plperl' with (isstrict);
CREATE FUNCTION
jeff=# SELECT s('abc 123','([^ ]*) (.*)','$2 $1');
ERROR:  creation of function failed: eval "string"
trapped by operation mask at (eval 4) line 1.

Looks like you just can't do it with pl/perl, because
"eval" is blocked for safety reasons.  If using an
untrusted language is not an issue for you, you should
be able to do what you want using pl/perlu (untrusted
perl).

I believe you can install pl/perlu in just the same
way as installing pl/perl.  You will probably need to
drop pl/perl first though.

--- Nabil Sayegh <postgresql@e-trolley.de> wrote:
> Jeff Eckermann wrote:
> > Perhaps if you could post a "real" example, you
> might
> > get more useful help.
>
> Here we go:
>
> SELECT s('abc 123','([^ ]*) (.*)','$2 $1');
>
> This regex should swaps 2 columns seperated by 1
> space.
>
> For the moment I harcoded my regex in a special
> function, but I would be
> delighted if it would be possible (without the use
> of eval) to have
> arbitrary regular expression search-replace.
>
> I don't think we're getting off-topic as too many
> ppl have asked this
> question already and always the answer has been: Use
> PL/Perl
>
> cu
> --
>   e-Trolley Sayegh & John, Nabil Sayegh
>   Tel.: 0700 etrolley /// 0700 38765539
>   Fax.: +49 69 8299381-8
>   PGP : http://www.e-trolley.de
>


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

pgsql-novice by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Serial Column Tweaking
Next
From: Josh Berkus
Date:
Subject: Re: Trigger return value