]> granicus.if.org Git - postgresql/commitdiff
PL/Python: Update example
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 18 Jan 2012 19:02:09 +0000 (21:02 +0200)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 18 Jan 2012 19:02:09 +0000 (21:02 +0200)
Change the usesavedplan() example to use a more modern Python style
using the .setdefault() function.

doc/src/sgml/plpython.sgml

index 618f8d055e919ba6ec4dae651fcbe1608e80b107..5a3c8caa689efcfcdc0094ddab1b32424dbd07ab 100644 (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>