I've ran into this interesting problem.
It seems that while you can call sort() in a trusted plperl func you cannot access $a & $b which effectively makes it useless.

I've tested this on 8.2.11, 8.3.5, and the nov 4 snapshot on ftp.postgresql.org
In all cases its on a mac with perl 5.8.8.

I also tested on Linux with 8.2.5 (yes yes, I know I need to upgrade!) with the same results.

Is this intended behavior?


create or replace function trustedsort()
returns int
as $$

my @arr = (5, 4, 3, 2, 1);

my @sorted = sort { elog(NOTICE, "$a $b"); $a <=> $b } @arr;

return 1;

$$
language 'plperl';

create or replace function untrustedsort()
returns int
as $$

my @arr = (5, 4, 3, 2, 1);

my @sorted = sort { elog(NOTICE, "$a $b"); $a <=> $b } @arr;

return 1;

$$
language 'plperlu';


select trustedsort();
select untrustedsort();

drop function trustedsort();
drop function untrustedsort();

----

CREATE FUNCTION
CREATE FUNCTION
psql:stupid_plperl.sql:28: NOTICE:
psql:stupid_plperl.sql:28: NOTICE:
psql:stupid_plperl.sql:28: NOTICE:
psql:stupid_plperl.sql:28: NOTICE:
psql:stupid_plperl.sql:28: NOTICE:
psql:stupid_plperl.sql:28: NOTICE:
psql:stupid_plperl.sql:28: NOTICE:
psql:stupid_plperl.sql:28: NOTICE:
 trustedsort
-------------
           1
(1 row)

psql:stupid_plperl.sql:29: NOTICE:  5 4
psql:stupid_plperl.sql:29: NOTICE:  3 2
psql:stupid_plperl.sql:29: NOTICE:  4 2
psql:stupid_plperl.sql:29: NOTICE:  4 3
psql:stupid_plperl.sql:29: NOTICE:  2 1
 untrustedsort
---------------
             1
(1 row)

DROP FUNCTION
DROP FUNCTION

--
Jeff Trout <[EMAIL PROTECTED]>
http://www.stuarthamm.net/
http://www.dellsmartexitin.com/




--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to