mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03:00
PL/Python: Update example
Change the usesavedplan() example to use a more modern Python style using the .setdefault() function.
This commit is contained in:
@ -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>
|
||||||
|
Reference in New Issue
Block a user