From a8cb3368db96d2492c3dce6ae2a3b7a69c11de90 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 7 Apr 2003 01:29:26 +0000 Subject: General editing --- doc/src/sgml/plpython.sgml | 74 ++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 35 deletions(-) (limited to 'doc/src/sgml/plpython.sgml') diff --git a/doc/src/sgml/plpython.sgml b/doc/src/sgml/plpython.sgml index 7a36c074dca..6ec19c6e8ea 100644 --- a/doc/src/sgml/plpython.sgml +++ b/doc/src/sgml/plpython.sgml @@ -1,4 +1,4 @@ - + PL/Python - Python Procedural Language @@ -17,11 +17,18 @@ createlang plpython dbname. + + + If a language is installed into template1, all subsequently + created databases will have the language installed automatically. + + + Users of source packages must specially enable the build of - PL/Python during the installation process (refer to the - installation instructions for more information). Users of binary + PL/Python during the installation process. (Refer to the + installation instructions for more information.) Users of binary packages might find PL/Python in a separate subpackage. @@ -30,11 +37,11 @@ PL/Python Functions - The Python code you write gets transformed into a function. E.g., + The Python code you write gets transformed into a Python function. E.g., CREATE FUNCTION myfunc(text) RETURNS text AS 'return args[0]' - LANGUAGE 'plpython'; + LANGUAGE plpython; gets transformed into @@ -49,7 +56,7 @@ def __plpython_procedure_myfunc_23456(): If you do not provide a return value, Python returns the default - None which may or may not be what you want. The + None. The language module translates Python's None into the SQL null value. @@ -60,8 +67,8 @@ def __plpython_procedure_myfunc_23456(): myfunc example, args[0] contains whatever was passed in as the text argument. For myfunc2(text, integer), args[0] - would contain the text variable and - args[1] the integer variable. + would contain the text argument and + args[1] the integer argument. @@ -95,14 +102,14 @@ def __plpython_procedure_myfunc_23456(): TD["level"] contains one of ROW, STATEMENT, and UNKNOWN. TD["name"] contains the trigger name, and - TD["relid"] contains the relation ID of the table on + TD["relid"] contains the OID of the table on which the trigger occurred. If the trigger was called with arguments they are available in TD["args"][0] to TD["args"][(n-1)]. - If the TD["when"] is BEFORE, you may + If TD["when"] is BEFORE, you may return None or "OK" from the Python function to indicate the row is unmodified, "SKIP" to abort the event, or "MODIFY" to @@ -147,10 +154,10 @@ def __plpython_procedure_myfunc_23456(): optional limit argument causes that query to be run and the result to be returned in a result object. The result object emulates a list or dictionary object. The result object can be accessed by - row number and field name. It has these additional methods: - nrows() which returns the number of rows + row number and column name. It has these additional methods: + nrows which returns the number of rows returned by the query, and status which is the - SPI_exec return variable. The result object + SPI_exec() return value. The result object can be modified. @@ -161,27 +168,27 @@ rv = plpy.execute("SELECT * FROM my_table", 5) returns up to 5 rows from my_table. If my_table has a column - my_field, it would be accessed as + my_column, it would be accessed as -foo = rv[i]["my_field"] +foo = rv[i]["my_column"] - The second function plpy.prepare is called - with a query string and a list of argument types if you have bind - variables in the query. For example: + The second function, plpy.prepare, prepares the + execution plan for a query. It is called with a query string and a + list of parameter types, if you have parameter references in the + query. For example: plan = plpy.prepare("SELECT last_name FROM my_users WHERE first_name = $1", [ "text" ]) text is the type of the variable you will be - passing as $1. After preparing a statement, you + passing for $1. After preparing a statement, you use the function plpy.execute to run it: rv = plpy.execute(plan, [ "name" ], 5) - The limit argument is optional in the call to - plpy.execute. + The third argument is the limit and is optional. @@ -190,7 +197,7 @@ rv = plpy.execute(plan, [ "name" ], 5) in the immediate termination of that function by the server; it is not possible to trap error conditions using Python try ... catch constructs. For example, a syntax error in an - SQL statement passed to the plpy.execute() call + SQL statement passed to the plpy.execute call will terminate the function. This behavior may be changed in a future release. @@ -199,22 +206,19 @@ rv = plpy.execute(plan, [ "name" ], 5) When you prepare a plan using the PL/Python module it is automatically saved. Read the SPI documentation () for a description of what this means. - - - In order to make effective use of this across function calls one needs to use one of the persistent storage dictionaries - SD or GD, see - . For example: + SD or GD (see + ). For example: -CREATE FUNCTION usesavedplan ( ) RETURNS TRIGGER AS ' - if SD.has_key("plan"): - plan = SD["plan"] - else: - plan = plpy.prepare("SELECT 1") - SD["plan"] = plan - # rest of function -' LANGUAGE 'plpython'; +CREATE FUNCTION usesavedplan() RETURNS trigger AS ' + if SD.has_key("plan"): + plan = SD["plan"] + else: + plan = plpy.prepare("SELECT 1") + SD["plan"] = plan + # rest of function +' LANGUAGE plpython; -- cgit v1.2.3