Functions in PL/Python are declared via the usual
syntax. For example:
CREATE FUNCTION myfunc(text) RETURNS text
AS 'return args'
The Python code that is given as the body of the function definition gets transformed into a Python function. For example, the above results in
assuming that 23456 is the OID assigned to the function by PostgreSQL.
If you do not provide a return value, Python returns the default None. PL/Python translates Python's None into the SQL null value.
The PostgreSQL function parameters are available in the global args list. In the
myfunc example, args contains whatever was passed in as the text argument. For myfunc2(text, integer), args would contain the text argument and args the integer argument.
The global dictionary SD is available to store data between function calls. This variable is private static data. The global dictionary GD is public data, available to all Python functions within a session. Use with care.
Each function gets its own execution environment in the Python interpreter, so that global data and function arguments from
myfunc are not available to
myfunc2. The exception is the data in the GD dictionary, as mentioned above.