Hello it isn't surprise. PL/pgSQL hasn't own arithmetic unit. All expressions are transformed to simple SELECTs. Probably you can find a tasks, where Perl should be 10, 100, 1000x faster than PL/pgSQL - array sort, array creation, .. On second hand, PL/pgSQL is very fast with embeded SQL. So if you need to calculate a numeric expensive task, then you need to use Perl, maybe Python or C. If you need to join a embedded SQL, then PL/pgSQL is good tool. Regards Pavel Stehule p.s. Once I had to solve very slow statistical analysis. 99% of time needed a bublesort implemented in PL/pgSQL. When I replaced it by buildin quicksort in SQL language, the problem was solved. 2011/2/8 pasman pasmaÅski <pasman.p@xxxxxxxxx>: > Hi. > I do small test of plsql and perl.Result is that perl may be > 2xfaster in simple loops. > > > CREATE OR REPLACE FUNCTION _.test1() ÂRETURNS void AS > $BODY$ > declare Âi integer; Âj bigint := 0; > begin > for i in 1..1000000 loop Âj:=j+i; end loop; > end; > $BODY$ LANGUAGE plpgsql VOLATILE ÂCOST 100; > > "Result Â(cost=0.00..0.26 rows=1 width=0) (actual > time=1382.851..1382.853 rows=1 loops=1)" > "Total runtime: 1383.167 ms" > > > CREATE OR REPLACE FUNCTION _.test2() ÂRETURNS void AS > $BODY$ > $j=0; > for($i=0;$i<1000000;$i++) { > Â Â$j = $j + $i; > } > $BODY$ ÂLANGUAGE plperlu VOLATILE COST 100; > > "Result Â(cost=0.00..0.26 rows=1 width=0) (actual > time=584.272..584.275 rows=1 loops=1)" > "Total runtime: 584.355 ms" > > > ------------ > pasman > > -- > Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-performance > -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance