Re: Install new perl test function in PostgreSQL

From: Michael Wood <esiotrot(at)gmail(dot)com>
To: Jignesh Shah <jignesh(dot)shah1980(at)gmail(dot)com>
Cc: Jure Kobal <j(dot)kobal(at)gmx(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Install new perl test function in PostgreSQL
Date: 2009-08-26 07:01:56
Message-ID: 5a8aa6680908260001q6e0418c6y31cc8689fd6eb3bf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

2009/8/26 Jignesh Shah <jignesh(dot)shah1980(at)gmail(dot)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(at)gmail(dot)com>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Ridvan Lakas ng Bayan S. Baluyos 2009-08-26 09:34:53 [novice] Segmentation Fault Error
Previous Message Jignesh Shah 2009-08-26 06:33:01 Writting Trigger for Truncate event