|
1 |
| -<!-- $Header: /cvsroot/pgsql/doc/src/sgml/plpython.sgml,v 1.14 2002/09/23 01:51:02 momjian Exp $ --> |
| 1 | +<!-- $Header: /cvsroot/pgsql/doc/src/sgml/plpython.sgml,v 1.15 2002/10/21 20:34:09 momjian Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="plpython">
|
4 | 4 | <title>PL/Python - Python Procedural Language</title>
|
@@ -198,15 +198,24 @@ rv = plpy.execute(plan, [ "name" ], 5)
|
198 | 198 | <para>
|
199 | 199 | When you prepare a plan using the PL/Python module it is
|
200 | 200 | automatically saved. Read the SPI documentation (<xref
|
201 |
| - linkend="spi">) for a description of what this means. The take |
202 |
| - home message is if you do |
| 201 | + linkend="spi">) for a description of what this means. |
| 202 | + </para> |
| 203 | + |
| 204 | + <para> |
| 205 | + In order to make effective use of this across function calls |
| 206 | + one needs to use one of the persistent storage dictionaries |
| 207 | + <literal>SD</literal> or <literal>GD</literal>, see |
| 208 | + <xref linkend="plpython-funcs">. For example: |
203 | 209 | <programlisting>
|
204 |
| -plan = plpy.prepare("SOME QUERY") |
205 |
| -plan = plpy.prepare("SOME OTHER QUERY") |
| 210 | +CREATE FUNCTION usesavedplan ( ) RETURNS TRIGGER AS ' |
| 211 | + if SD.has_key("plan"): |
| 212 | + plan = SD["plan"] |
| 213 | + else: |
| 214 | + plan = plpy.prepare("SELECT 1") |
| 215 | + SD["plan"] = plan |
| 216 | + # rest of function |
| 217 | +' LANGUAGE 'plpython'; |
206 | 218 | </programlisting>
|
207 |
| - you are leaking memory, as I know of no way to free a saved plan. |
208 |
| - The alternative of using unsaved plans it even more painful (for |
209 |
| - me). |
210 | 219 | </para>
|
211 | 220 | </sect1>
|
212 | 221 |
|
|