Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdfdae5d

Browse files
committed
Hook up the plpython result-object nrows and status methods correctly.
Adjust documentation to match current reality.
1 parentff5a354 commitdfdae5d

File tree

2 files changed

+29
-56
lines changed

2 files changed

+29
-56
lines changed

‎doc/src/sgml/plpython.sgml

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.24 2004/09/13 20:05:18 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.25 2004/12/17 02:14:44 tgl Exp $ -->
22

33
<chapter id="plpython">
44
<title>PL/Python - Python Procedural Language</title>
@@ -46,7 +46,8 @@
4646
<title>PL/Python Functions</title>
4747

4848
<para>
49-
The Python code you write gets transformed into a Python function. E.g.,
49+
The Python code you write gets transformed into a Python function.
50+
For example,
5051
<programlisting>
5152
CREATE FUNCTION myfunc(text) RETURNS text
5253
AS 'return args[0]'
@@ -60,13 +61,14 @@ def __plpython_procedure_myfunc_23456():
6061
return args[0]
6162
</programlisting>
6263

63-
assuming that 23456 is the OID of the function.
64+
assuming that 23456 is the OID assigned to the function by
65+
<productname>PostgreSQL</productname>.
6466
</para>
6567

6668
<para>
6769
If you do not provide a return value, Python returns the default
68-
<symbol>None</symbol>.The language moduletranslates Python's
69-
<symbol>None</symbol> into the SQL null
70+
<symbol>None</symbol>.<application>PL/Python</application>translates
71+
Python's<symbol>None</symbol> into the SQL null
7072
value.<indexterm><primary>null value</><secondary
7173
sortas="PL/Python">in PL/Python</></indexterm>
7274
</para>
@@ -108,7 +110,7 @@ def __plpython_procedure_myfunc_23456():
108110
</indexterm>
109111

110112
<para>
111-
When a function is usedin a trigger, the dictionary
113+
When a function is usedas a trigger, the dictionary
112114
<literal>TD</literal> contains trigger-related values. The trigger
113115
rows are in <literal>TD["new"]</> and/or <literal>TD["old"]</>
114116
depending on the trigger event. <literal>TD["event"]</> contains
@@ -120,9 +122,9 @@ def __plpython_procedure_myfunc_23456():
120122
<literal>STATEMENT</>, and <literal>UNKNOWN</>.
121123
<literal>TD["name"]</> contains the trigger name, and
122124
<literal>TD["relid"]</> contains the OID of the table on
123-
which the trigger occurred. If thetrigger was called with
124-
arguments they are available in <literal>TD["args"][0]</> to
125-
<literal>TD["args"][(n-1)]</>.
125+
which the trigger occurred. If the<command>CREATE TRIGGER</> command
126+
includedarguments, they are available in <literal>TD["args"][0]</> to
127+
<literal>TD["args"][(<replaceable>n</>-1)]</>.
126128
</para>
127129

128130
<para>
@@ -143,23 +145,23 @@ def __plpython_procedure_myfunc_23456():
143145
this module are available to you in the Python code as
144146
<literal>plpy.<replaceable>foo</replaceable></literal>. At present
145147
<literal>plpy</literal> implements the functions
146-
<literal>plpy.debug("msg")</literal>,
147-
<literal>plpy.log("msg")</literal>,
148-
<literal>plpy.info("msg")</literal>,
149-
<literal>plpy.notice("msg")</literal>,
150-
<literal>plpy.warning("msg")</literal>,
151-
<literal>plpy.error("msg")</literal>, and
152-
<literal>plpy.fatal("msg")</literal>. They are mostly equivalent
153-
to calling <literal>elog(<replaceable>LEVEL</>, "msg")</literal>
148+
<literal>plpy.debug(<replaceable>msg</>)</literal>,
149+
<literal>plpy.log(<replaceable>msg</>)</literal>,
150+
<literal>plpy.info(<replaceable>msg</>)</literal>,
151+
<literal>plpy.notice(<replaceable>msg</>)</literal>,
152+
<literal>plpy.warning(<replaceable>msg</>)</literal>,
153+
<literal>plpy.error(<replaceable>msg</>)</literal>, and
154+
<literal>plpy.fatal(<replaceable>msg</>)</literal>.
155+
These are mostly equivalent to calling
156+
<literal>elog(<replaceable>level</>, <replaceable>msg</>)</literal>
154157
from C code.<indexterm><primary>elog</><secondary>in
155158
PL/Python</></indexterm> <function>plpy.error</function> and
156159
<function>plpy.fatal</function> actually raise a Python exception
157160
which, if uncaught, causes the PL/Python module to call
158161
<literal>elog(ERROR, msg)</literal> when the function handler
159-
returns from the Python interpreter. Long-jumping out of the
160-
Python interpreter is probably not good. <literal>raise
161-
plpy.ERROR("msg")</literal> and <literal>raise
162-
plpy.FATAL("msg")</literal> are equivalent to calling
162+
returns from the Python interpreter. <literal>raise
163+
plpy.ERROR(<replaceable>msg</>)</literal> and <literal>raise
164+
plpy.FATAL(<replaceable>msg</>)</literal> are equivalent to calling
163165
<function>plpy.error</function> and
164166
<function>plpy.fatal</function>, respectively.
165167
</para>
@@ -210,17 +212,6 @@ rv = plpy.execute(plan, [ "name" ], 5)
210212
The third argument is the limit and is optional.
211213
</para>
212214

213-
<para>
214-
In the current version, any database error encountered while
215-
running a <application>PL/Python</application> function will result
216-
in the immediate termination of that function by the server; it is
217-
not possible to trap error conditions using Python <literal>try
218-
... catch</literal> constructs. For example, a syntax error in an
219-
SQL statement passed to the <literal>plpy.execute</literal> call
220-
will terminate the function. This behavior may be changed in a
221-
future release.
222-
</para>
223-
224215
<para>
225216
When you prepare a plan using the PL/Python module it is
226217
automatically saved. Read the SPI documentation (<xref

‎src/pl/plpython/plpython.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
3030
*
3131
* IDENTIFICATION
32-
*$PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.57 2004/09/19 23:38:21 tgl Exp $
32+
*$PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.58 2004/12/17 02:14:48 tgl Exp $
3333
*
3434
*********************************************************************
3535
*/
@@ -1531,13 +1531,8 @@ static PyObject *PLy_plan_status(PyObject *, PyObject *);
15311531
staticPyObject*PLy_result_new(void);
15321532
staticvoidPLy_result_dealloc(PyObject*);
15331533
staticPyObject*PLy_result_getattr(PyObject*,char*);
1534-
1535-
#ifdefNOT_USED
1536-
/* Appear to be unused */
1537-
staticPyObject*PLy_result_fetch(PyObject*,PyObject*);
15381534
staticPyObject*PLy_result_nrows(PyObject*,PyObject*);
15391535
staticPyObject*PLy_result_status(PyObject*,PyObject*);
1540-
#endif
15411536
staticintPLy_result_length(PyObject*);
15421537
staticPyObject*PLy_result_item(PyObject*,int);
15431538
staticPyObject*PLy_result_slice(PyObject*,int,int);
@@ -1582,7 +1577,7 @@ static PyTypeObject PLy_PlanType = {
15821577
};
15831578

15841579
staticPyMethodDefPLy_plan_methods[]= {
1585-
{"status",(PyCFunction)PLy_plan_status,METH_VARARGS,NULL},
1580+
{"status",PLy_plan_status,METH_VARARGS,NULL},
15861581
{NULL,NULL,0,NULL}
15871582
};
15881583

@@ -1626,15 +1621,11 @@ static PyTypeObject PLy_ResultType = {
16261621
PLy_result_doc,/* tp_doc */
16271622
};
16281623

1629-
#ifdefNOT_USED
1630-
/* Appear to be unused */
16311624
staticPyMethodDefPLy_result_methods[]= {
1632-
{"fetch", (PyCFunction)PLy_result_fetch,METH_VARARGS,NULL,},
1633-
{"nrows", (PyCFunction)PLy_result_nrows,METH_VARARGS,NULL},
1634-
{"status", (PyCFunction)PLy_result_status,METH_VARARGS,NULL},
1625+
{"nrows",PLy_result_nrows,METH_VARARGS,NULL},
1626+
{"status",PLy_result_status,METH_VARARGS,NULL},
16351627
{NULL,NULL,0,NULL}
16361628
};
1637-
#endif
16381629

16391630
staticPyMethodDefPLy_methods[]= {
16401631
/*
@@ -1758,17 +1749,9 @@ PLy_result_dealloc(PyObject * arg)
17581749
}
17591750

17601751
staticPyObject*
1761-
PLy_result_getattr(PyObject*self,char*attr)
1752+
PLy_result_getattr(PyObject*self,char*name)
17621753
{
1763-
returnNULL;
1764-
}
1765-
1766-
#ifdefNOT_USED
1767-
/* Appear to be unused */
1768-
staticPyObject*
1769-
PLy_result_fetch(PyObject*self,PyObject*args)
1770-
{
1771-
returnNULL;
1754+
returnPy_FindMethod(PLy_result_methods,self,name);
17721755
}
17731756

17741757
staticPyObject*
@@ -1788,7 +1771,6 @@ PLy_result_status(PyObject * self, PyObject * args)
17881771
Py_INCREF(ob->status);
17891772
returnob->status;
17901773
}
1791-
#endif
17921774

17931775
staticint
17941776
PLy_result_length(PyObject*arg)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp