From af8756713fcbbf907954b7a77072229910662520 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Mon, 4 Jul 2005 19:03:30 +0000 Subject: 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 --- src/pl/plpython/plpython.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/pl/plpython/plpython.c') diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c index b749e02f878..52ad1775829 100644 --- a/src/pl/plpython/plpython.c +++ b/src/pl/plpython/plpython.c @@ -29,7 +29,7 @@ * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.62 2005/05/06 17:24:55 tgl Exp $ + * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.63 2005/07/04 18:59:42 momjian Exp $ * ********************************************************************* */ @@ -286,6 +286,9 @@ static PyObject *PLy_exc_error = NULL; static PyObject *PLy_exc_fatal = NULL; static PyObject *PLy_exc_spi_error = NULL; +/* End-of-set Indication */ +static PyObject *PLy_endofset = NULL; + /* some globals for the python module */ static char PLy_plan_doc[] = { @@ -770,6 +773,16 @@ PLy_function_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) fcinfo->isnull = true; rv = (Datum) NULL; } + /* test for end-of-set condition */ + else if (fcinfo->flinfo->fn_retset && plrv == PLy_endofset) + { + ReturnSetInfo *rsi; + + fcinfo->isnull = true; + rv = (Datum)NULL; + rsi = (ReturnSetInfo *)fcinfo->resultinfo; + rsi->isDone = ExprEndResult; + } else { fcinfo->isnull = false; @@ -2317,9 +2330,11 @@ PLy_init_plpy(void) PLy_exc_error = PyErr_NewException("plpy.Error", NULL, NULL); PLy_exc_fatal = PyErr_NewException("plpy.Fatal", NULL, NULL); PLy_exc_spi_error = PyErr_NewException("plpy.SPIError", NULL, NULL); + PLy_endofset = PyErr_NewException("plpy.EndOfSet",NULL,NULL); PyDict_SetItemString(plpy_dict, "Error", PLy_exc_error); PyDict_SetItemString(plpy_dict, "Fatal", PLy_exc_fatal); PyDict_SetItemString(plpy_dict, "SPIError", PLy_exc_spi_error); + PyDict_SetItemString(plpy_dict, "EndOfSet", PLy_endofset); /* * initialize main module, and add plpy -- cgit v1.2.3