Commit 6f6b46c9 authored by Peter Eisentraut's avatar Peter Eisentraut

PL/Python: Update example

Change the usesavedplan() example to use a more modern Python style
using the .setdefault() function.
parent 326b922e
...@@ -955,11 +955,7 @@ rv = plpy.execute(plan, [ "name" ], 5) ...@@ -955,11 +955,7 @@ rv = plpy.execute(plan, [ "name" ], 5)
<xref linkend="plpython-sharing">). For example: <xref linkend="plpython-sharing">). For example:
<programlisting> <programlisting>
CREATE FUNCTION usesavedplan() RETURNS trigger AS $$ CREATE FUNCTION usesavedplan() RETURNS trigger AS $$
if SD.has_key("plan"): plan = SD.setdefault("plan", plpy.prepare("SELECT 1"))
plan = SD["plan"]
else:
plan = plpy.prepare("SELECT 1")
SD["plan"] = plan
# rest of function # rest of function
$$ LANGUAGE plpythonu; $$ LANGUAGE plpythonu;
</programlisting> </programlisting>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment