1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5 >PL/Python - Python Procedural Language</TITLE
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
10 HREF="mailto:pgsql-docs@postgresql.org"><LINK
12 TITLE="PostgreSQL 7.4.1 Documentation"
13 HREF="index.html"><LINK
15 TITLE="Server Programming"
16 HREF="server-programming.html"><LINK
18 TITLE="Missing Features"
19 HREF="plperl-missing.html"><LINK
21 TITLE="Trigger Functions"
22 HREF="plpython-trigger.html"><LINK
25 HREF="stylesheet.css"><META
27 CONTENT="2003-12-22T03:48:47"></HEAD
33 SUMMARY="Header navigation table"
43 >PostgreSQL 7.4.1 Documentation</TH
51 HREF="plperl-missing.html"
81 HREF="plpython-trigger.html"
96 >Chapter 40. PL/Python - Python Procedural Language</H1
102 >Table of Contents</B
106 HREF="plpython.html#PLPYTHON-FUNCS"
107 >PL/Python Functions</A
111 HREF="plpython-trigger.html"
112 >Trigger Functions</A
116 HREF="plpython-database.html"
131 > procedural language allows
135 > functions to be written in the
137 HREF="http://www.python.org"
143 > To install PL/Python in a particular database, use
146 >createlang plpythonu <VAR
159 > If a language is installed into <TT
163 created databases will have the language installed automatically.
171 > 7.4, PL/Python is only
172 available as an <SPAN
175 > language (meaning it does not
176 offer any way of restricting what users can do in it). It has
177 therefore been renamed to <TT
184 > may become available again in future,
185 if a new secure execution mechanism is developed in Python.
194 > Users of source packages must specially enable the build of
195 PL/Python during the installation process. (Refer to the
196 installation instructions for more information.) Users of binary
197 packages might find PL/Python in a separate subpackage.
206 NAME="PLPYTHON-FUNCS"
207 >40.1. PL/Python Functions</A
210 > The Python code you write gets transformed into a Python function. E.g.,
212 CLASS="PROGRAMLISTING"
213 >CREATE FUNCTION myfunc(text) RETURNS text
215 LANGUAGE plpythonu;</PRE
218 gets transformed into
221 CLASS="PROGRAMLISTING"
222 >def __plpython_procedure_myfunc_23456():
226 assuming that 23456 is the OID of the function.
229 > If you do not provide a return value, Python returns the default
233 >. The language module translates Python's
247 > function parameters are available in
259 whatever was passed in as the text argument. For
262 >myfunc2(text, integer)</TT
267 would contain the <TT
280 > The global dictionary <VAR
283 > is available to store
284 data between function calls. This variable is private static data.
285 The global dictionary <VAR
289 available to all Python functions within a session. Use with
296 > Each function gets its own execution environment in the
297 Python interpreter, so that global data and function arguments from
301 > are not available to
305 >. The exception is the data in the
309 > dictionary, as mentioned above.
318 SUMMARY="Footer navigation table"
329 HREF="plperl-missing.html"
347 HREF="plpython-trigger.html"
357 >Missing Features</TD
363 HREF="server-programming.html"
371 >Trigger Functions</TD