
Using PL/Perl from Advanced Server
====================================
The PL/Perl procedural language allows Advanced Server users to use Perl functions 
in Advanced Server applications. Before using PL/Perl with Advanced Server, you 
must install Perl.

For Linux and Windows you must download and run the ActivePerl installer available 
through:

     www.activestate.com/activeperl/downloads/

  For Solaris, download and install any available 64bit Perl package.

Linux and Solaris users: after installing Perl, you must update the LD_LIBRARY_PATH 
variable to include the path to the Perl shared library libperl.so.  Use the command:

     export LD_LIBRARY_PATH=<path-to-perl-library>:$LD_LIBRARY_PATH

This command does not persistently alter the value of LD_LIBRARY_PATH; consult the 
documentation for your distribution of Linux for information about persistently setting 
the value of LD_LIBRARY_PATH. 
    
After installing PL/Perl and setting the library path (if required), you must restart 
the Advanced Server service.  Please see the Postgres Plus Advanced Server Installation Guide 
for information about restarting the Advanced Server service.    

PL/Perl is distributed with Postgres Plus Advanced Server.  You must install PL/Perl in each 
database (or in a template database) before creating a PL/Perl function.  Use the CREATE 
LANGUAGE command at the EDB-PSQL command line to install PL/Perl.  To open an EDB-PSQL 
terminal window, navigate through the Postgres Plus Advanced Server menu to the Run SQL 
Command Line menu, and select EDB-PSQL.  After connecting to an instance of Advanced Server, 
enter the command:

    CREATE LANGUAGE plperl;

  Advanced Server confirms that the language is loaded with the response:

    CREATE LANGUAGE        
    
You can now use the features of the PL/Perl language from within Advanced Server.  The 
following PL/Perl example creates a function named perl_max that returns the larger of 
two integer values:

    CREATE OR REPLACE FUNCTION perl_max (integer, integer) RETURNS integer AS 
    $$
        if ($_[0] > $_[1]) 
          { return $_[0]; }

        return $_[1];
    $$ LANGUAGE plperl;

  Use the following commands to call the function:

    SELECT perl_max(1, 2);

  or

    SELECT perl_max(1, null);


Resources
---------
For more information about using the Perl procedural language with Advanced Server, 
consult the official Postgres documentation, available from EnterpriseDB at:

    www.enterprisedb.com/products-services-training/products/documentation



