Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit af87567

Browse files
committed
This patch allows the PL/Python module to do (SRF) functions.
The patch was taken from the CVS version. I have modified the plpython.c file and have added a test sql script for testing the functionality. It was actually the script that was in the 8.0.3 version but have since been removed. In order to signal the end of a set, the called python function must simply return plpy.EndOfSet and the set would be returned. Gerrit van Dyk
1 parent 109f079 commit af87567

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/pl/plpython/plpython.c

Lines changed: 16 additions & 1 deletion
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.62 2005/05/06 17:24:55 tgl Exp $
32+
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.63 2005/07/04 18:59:42 momjian Exp $
3333
*
3434
*********************************************************************
3535
*/
@@ -286,6 +286,9 @@ static PyObject *PLy_exc_error = NULL;
286286
static PyObject *PLy_exc_fatal = NULL;
287287
static PyObject *PLy_exc_spi_error = NULL;
288288

289+
/* End-of-set Indication */
290+
static PyObject *PLy_endofset = NULL;
291+
289292
/* some globals for the python module
290293
*/
291294
static char PLy_plan_doc[] = {
@@ -770,6 +773,16 @@ PLy_function_handler(FunctionCallInfo fcinfo, PLyProcedure * proc)
770773
fcinfo->isnull = true;
771774
rv = (Datum) NULL;
772775
}
776+
/* test for end-of-set condition */
777+
else if (fcinfo->flinfo->fn_retset && plrv == PLy_endofset)
778+
{
779+
ReturnSetInfo *rsi;
780+
781+
fcinfo->isnull = true;
782+
rv = (Datum)NULL;
783+
rsi = (ReturnSetInfo *)fcinfo->resultinfo;
784+
rsi->isDone = ExprEndResult;
785+
}
773786
else
774787
{
775788
fcinfo->isnull = false;
@@ -2317,9 +2330,11 @@ PLy_init_plpy(void)
23172330
PLy_exc_error = PyErr_NewException("plpy.Error", NULL, NULL);
23182331
PLy_exc_fatal = PyErr_NewException("plpy.Fatal", NULL, NULL);
23192332
PLy_exc_spi_error = PyErr_NewException("plpy.SPIError", NULL, NULL);
2333+
PLy_endofset = PyErr_NewException("plpy.EndOfSet",NULL,NULL);
23202334
PyDict_SetItemString(plpy_dict, "Error", PLy_exc_error);
23212335
PyDict_SetItemString(plpy_dict, "Fatal", PLy_exc_fatal);
23222336
PyDict_SetItemString(plpy_dict, "SPIError", PLy_exc_spi_error);
2337+
PyDict_SetItemString(plpy_dict, "EndOfSet", PLy_endofset);
23232338

23242339
/*
23252340
* initialize main module, and add plpy
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
CREATE or replace FUNCTION test_setof() returns setof text
3+
AS
4+
'if GD.has_key("calls"):
5+
GD["calls"] = GD["calls"] + 1
6+
if GD["calls"] > 2:
7+
del GD["calls"]
8+
return plpy.EndOfSet
9+
else:
10+
GD["calls"] = 1
11+
return str(GD["calls"])'
12+
LANGUAGE plpythonu;

0 commit comments

Comments
 (0)