Skip site navigation (1) Skip section navigation (2)

Re: plperl: sort trapped by operation mask

From: Reece Hart <reece(at)harts(dot)net>
To: SF PostgreSQL <sfpug(at)postgresql(dot)org>
Subject: Re: plperl: sort trapped by operation mask
Date: 2005-10-06 02:31:52
Message-ID: (view raw, whole thread or download thread mbox)
Lists: sfpug
On Wed, 2005-10-05 at 18:11 -0700, David Fetter wrote:

> It's untrusted in the context of s///e.


> my $NOT_RIGHT_BRACKET = qr([^\\]]+); # parse as regex 1st.
> s@
>     \\[($NOT_RIGHT_BRACKET)\\]
>  @
>     "[" .
>     join("", sort {$a cmp $b} (split(//, $1)) ) .
>     "]"
>  @egmx;


Kudos for digesting (and cleaning up) my obfuscated perl.

The code is intended to sort tokens within [] sets in a regexp. My
primary motivation is a canonical form for such regexps. For example, I
want A[BCBB][DEE] to become A[BC][DE]. The sort is required to get the
canonical ordering within []. (David's code is close to equivalent, but
without hashing tokens inside [], it won't compress multiple instances
of the same token.)

The problem is that sort apparently requires an untrusted language.

        => create or replace function sort_test() returns text
        strict immutable language plperl as '
        my @x = qw(c b a);
        return join("",sort @x);
        => select sort_test();
        ERROR:  creation of function failed: 'sort' trapped by operation mask at (eval 10) line 3.

The same function defined with plperlu (untrusted) works fine.

Surely I'm not the first one to try sort in a plperl function. And I
can't think of any reason for sort to require a trusted language.

I don't see anything specifically about sort and plperl/plperlu on the
web. Enlightenment, anyone?


Reece Hart,, GPG:0x25EC91A0

In response to


sfpug by date

Next:From: Reece HartDate: 2005-10-06 02:41:38
Subject: Re: plperl: sort trapped by operation mask
Previous:From: Jeff FrostDate: 2005-10-06 02:25:56
Subject: order of performance

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group