The plpy
module also provides the functions
plpy.debug(
,
msg
)plpy.log(
,
msg
)plpy.info(
,
msg
)plpy.notice(
,
msg
)plpy.warning(
,
msg
)plpy.error(
, and
msg
)plpy.fatal(
.
msg
)plpy.error
and
plpy.fatal
actually raise a Python exception
which, if uncaught, propagates out to the calling query, causing
the current transaction or subtransaction to be aborted.
raise plpy.Error(
and
msg
)raise plpy.Fatal(
are
equivalent to calling
msg
)plpy.error
and
plpy.fatal
, respectively.
The other functions only generate messages of different
priority levels.
Whether messages of a particular priority are reported to the client,
written to the server log, or both is controlled by the
log_min_messages and
client_min_messages configuration
variables. See Chapter 18, Server Configuration for more information.
Another set of utility functions are
plpy.quote_literal(
,
string
)plpy.quote_nullable(
, and
string
)plpy.quote_ident(
. They
are equivalent to the built-in quoting functions described in the section called “String Functions and Operators”. They are useful when constructing
ad-hoc queries. A PL/Python equivalent of dynamic SQL from Example 40.1, “Quoting Values In Dynamic Queries” would be:
string
)
plpy.execute("UPDATE tbl SET %s = %s WHERE key = %s" % ( plpy.quote_ident(colname), plpy.quote_nullable(newvalue), plpy.quote_literal(keyvalue)))