PL/Python: Update example

Change the usesavedplan() example to use a more modern Python style
using the .setdefault() function.
This commit is contained in:
Peter Eisentraut 2012-01-18 21:02:09 +02:00
parent 326b922e8b
commit 6f6b46c9c0

View File

@ -955,11 +955,7 @@ rv = plpy.execute(plan, [ "name" ], 5)
<xref linkend="plpython-sharing">). For example:
<programlisting>
CREATE FUNCTION usesavedplan() RETURNS trigger AS $$
if SD.has_key("plan"):
plan = SD["plan"]
else:
plan = plpy.prepare("SELECT 1")
SD["plan"] = plan
plan = SD.setdefault("plan", plpy.prepare("SELECT 1"))
# rest of function
$$ LANGUAGE plpythonu;
</programlisting>