Database Reference
In-Depth Information
Running this is much more verbose than the version with print, because each
NOTICE also includes information about the CONTEXT from where the NOTICE
comes:
hannu=# select fact(3);
NOTICE: f:3, x:2
CONTEXT: PL/Python function "fact"
NOTICE: f:6, x:1
CONTEXT: PL/Python function "fact"
NOTICE: f:6, x:0
CONTEXT: PL/Python function "fact"
fact
------
6
(1 row)
Tip
PL/Pythonu function arguments are passed in as globals
If you compared the fact(x) function in Python and PL/Python you noticed an
extra line at the beginning of the PL/Python function:
global x
This is needed to overcome an implementation detail that often surprises PL/
Pythonu developers; the function arguments are not the function arguments in
the Python sense and neither are they locals. They are passed in as variables in
the function's global scope.
Using assert
Similar to ordinary Python programming, you can also use Python's assert state-
ment to catch conditions which should not happen:
Search WWH ::




Custom Search