Re: Install new perl test function in PostgreSQL - Mailing list pgsql-novice

From Michael Wood
Subject Re: Install new perl test function in PostgreSQL
Date
Msg-id 5a8aa6680908260001q6e0418c6y31cc8689fd6eb3bf@mail.gmail.com
Whole thread Raw
In response to Re: Install new perl test function in PostgreSQL  (Jignesh Shah <jignesh.shah1980@gmail.com>)
Responses Re: Install new perl test function in PostgreSQL  (Jignesh Shah <jignesh.shah1980@gmail.com>)
List pgsql-novice
2009/8/26 Jignesh Shah <jignesh.shah1980@gmail.com>:
> Thanks Jure. I have already plperl installed because I could see that many
> new perl functions have been installed but I don't know where it plperl
> installed. Could you tell me if there is any way to find out where it is
> installed? Morever, if I get the location plperl install location, how to
> insert/install my perl function? Is there any command available for this. My
> questions might be silly but this is first time I am using PostgreSQL.

If it PL/Perl is installed in your database then you do not need to
know "where it is".  It's in your database.  So you can just create
your function and it should work.  e.g.:

$ psql dbname
Welcome to psql 8.3.1, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

dbname=> SELECT * FROM pg_language;
 lanname  | lanowner | lanispl | lanpltrusted | lanplcallfoid |
lanvalidator | lanacl
----------+----------+---------+--------------+---------------+--------------+--------
 internal |       10 | f       | f            |             0 |         2246 |
 c        |       10 | f       | f            |             0 |         2247 |
 sql      |       10 | f       | t            |             0 |         2248 |
(3 rows)

dbname=> CREATE LANGUAGE plperl;
CREATE LANGUAGE
dbname=> SELECT * FROM pg_language;
 lanname  | lanowner | lanispl | lanpltrusted | lanplcallfoid |
lanvalidator | lanacl
----------+----------+---------+--------------+---------------+--------------+--------
 internal |       10 | f       | f            |             0 |         2246 |
 c        |       10 | f       | f            |             0 |         2247 |
 sql      |       10 | f       | t            |             0 |         2248 |
 plperl   |    16386 | t       | t            |         19193 |        19194 |
(4 rows)

dbname=> CREATE FUNCTION perl_max (integer, integer) RETURNS integer AS $$
dbname$>     if ($_[0] > $_[1]) { return $_[0]; }
dbname$>     return $_[1];
dbname$> $$ LANGUAGE plperl;
CREATE FUNCTION
dbname=> SELECT perl_max(55, 23);
 perl_max
----------
       55
(1 row)

dbname=> SELECT perl_max(55, 97);
 perl_max
----------
       97
(1 row)

dbname=>

See also:
http://www.postgresql.org/docs/8.4/static/xplang.html
http://www.postgresql.org/docs/8.4/static/plperl.html

--
Michael Wood <esiotrot@gmail.com>

pgsql-novice by date:

Previous
From: Jignesh Shah
Date:
Subject: Writting Trigger for Truncate event
Next
From: "Ridvan Lakas ng Bayan S. Baluyos"
Date:
Subject: [novice] Segmentation Fault Error