Re: perlsub

From: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
To: Nabil Sayegh <postgresql(at)e-trolley(dot)de>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: perlsub
Date: 2003-10-07 19:46:59
Message-ID: 20031007194659.39415.qmail@web20801.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)e-trolley(dot)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

In response to

Responses

  • Re: perlsub at 2003-10-07 21:18:01 from Oliver Elphick

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2003-10-07 19:53:27 Re: Trigger return value
Previous Message Bruno Wolff III 2003-10-07 19:34:46 Re: Serial Column Tweaking