
Using PL/Python from Advanced Server
====================================
The PL/Python procedural language allows Advanced Server users to create  
(and execute) functions written in Python within Advanced Server applications.  
The version of PL/Python used by Advanced Server is untrusted (plpython3u); it 
offers no restrictions on users to prevent potential security risks. 

  For Linux and Windows, download and run the ActivePython installer (version 
  3.2.2.3 or greater), available through:

     www.activestate.com/activepython/downloads/

  For Solaris, download and install a 64-bit Python package 
  (version 3 or greater).

After downloading and installing the PL/Python package, you must:

  1. Update the PYTHONHOME environment variable, allowing Advanced Server 
     to locate the Python interpreter and runtime.  For example:

       export PYTHONHOME=/opt/ActivePython-3.2

     Please consult the documentation for your platform-specific information about 
     setting the value of environment variables.

  2. Restart the Advanced Server database server.  Please consult the Postgres Plus 
     Advanced Server Installation Guide for information about restarting the server.

  3. Install PL/Python in each database (or in a template database) before creating 
     a PL/Python function.  You can use the CREATE LANGUAGE command at the EDB-PSQL 
     command line to install PL/Python.  Start an EDB-PSQL session, and enter the 
     command:  

       CREATE LANGUAGE plpython3u;

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

       CREATE LANGUAGE        
    
You can now use the features of the PL/Python language from within Advanced 
Server.  

NOTE: The indentation shown in the example must be included as you enter the 
sample function in EDB-PSQL.  The following PL/Python example creates a 
function named pymax that returns the larger of two integer values:

    CREATE OR REPLACE FUNCTION pymax (a integer, b integer) RETURNS integer AS 
    $$
        if a > b:
          return a
        return b
    $$ LANGUAGE plpython3u;

  You can call the function (pymax), passing two values:

    SELECT pymax(1, 2);

  Advanced Server returns:

   pymax
  -------
      2
  (1 row)

  or:

    SELECT pymax(12, 3);

  Advanced Server returns:

   pymax
  -------
      12
  (1 row)
  

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

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