From: Bruce Momjian Date: Mon, 21 Oct 2002 20:34:09 +0000 (+0000) Subject: Small update for the removal of some memory leaks in plpython SGML example. X-Git-Tag: REL9_0_0~16481 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b6f0c50232afb441379ad02948a8c98180291ca3;p=pg-rex%2Fsyncrep.git Small update for the removal of some memory leaks in plpython SGML example. Nigel J. Andrews --- diff --git a/doc/src/sgml/plpython.sgml b/doc/src/sgml/plpython.sgml index f42c17e6fb..7a36c074dc 100644 --- a/doc/src/sgml/plpython.sgml +++ b/doc/src/sgml/plpython.sgml @@ -1,4 +1,4 @@ - + PL/Python - Python Procedural Language @@ -198,15 +198,24 @@ rv = plpy.execute(plan, [ "name" ], 5) When you prepare a plan using the PL/Python module it is automatically saved. Read the SPI documentation () for a description of what this means. The take - home message is if you do + linkend="spi">) for a description of what this means. + + + + In order to make effective use of this across function calls + one needs to use one of the persistent storage dictionaries + SD or GD, see + . For example: -plan = plpy.prepare("SOME QUERY") -plan = plpy.prepare("SOME OTHER QUERY") +CREATE FUNCTION usesavedplan ( ) RETURNS TRIGGER AS ' + if SD.has_key("plan"): + plan = SD["plan"] + else: + plan = plpy.prepare("SELECT 1") + SD["plan"] = plan + # rest of function +' LANGUAGE 'plpython'; - you are leaking memory, as I know of no way to free a saved plan. - The alternative of using unsaved plans it even more painful (for - me).