33 * procedural language
44 *
55 * IDENTIFICATION
6- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.33 2000/12/01 20:43:59 tgl Exp $
6+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.34 2001/01/04 02:38:02 tgl Exp $
77 *
88 * This software is copyrighted by Jan Wieck - Hamburg.
99 *
@@ -1951,6 +1951,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
19511951HeapTuple typetup ;
19521952Form_pg_type typeStruct ;
19531953FmgrInfo finfo_output ;
1954+ int exec_res ;
19541955
19551956/* ----------
19561957 * First we evaluate the string expression after the
@@ -1960,7 +1961,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
19601961 */
19611962query = exec_eval_expr (estate ,stmt -> query ,& isnull ,& restype );
19621963if (isnull )
1963- elog (ERROR ,"cannot EXECUTE NULL- query" );
1964+ elog (ERROR ,"cannot EXECUTE NULL query" );
19641965
19651966/* ----------
19661967 * Get the C-String representation.
@@ -1986,26 +1987,30 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
19861987
19871988/* ----------
19881989 * Call SPI_exec() without preparing a saved plan.
1989- * The returncode can be any OK except for OK_SELECT.
1990+ * The returncode can be any standard OK. Note that
1991+ * while a SELECT is allowed, its results will be discarded.
19901992 * ----------
19911993 */
1992- switch (SPI_exec (querystr ,0 ))
1994+ exec_res = SPI_exec (querystr ,0 );
1995+ switch (exec_res )
19931996{
1994- case SPI_OK_UTILITY :
1997+ case SPI_OK_SELECT :
19951998case SPI_OK_SELINTO :
19961999case SPI_OK_INSERT :
19972000case SPI_OK_UPDATE :
19982001case SPI_OK_DELETE :
2002+ case SPI_OK_UTILITY :
19992003break ;
20002004
2001- case SPI_OK_SELECT :
2002- elog (ERROR ,"unexpected SELECT operation in EXECUTE of query '%s'" ,
2003- querystr );
2005+ case 0 :
2006+ /* Also allow a zero return, which implies the querystring
2007+ * contained no commands.
2008+ */
20042009break ;
20052010
20062011default :
2007- elog (ERROR ,"unexpected error in EXECUTEfor query '%s'" ,
2008- querystr );
2012+ elog (ERROR ,"unexpected error%d in EXECUTEof query '%s'" ,
2013+ exec_res , querystr );
20092014break ;
20102015}
20112016
@@ -2095,7 +2100,7 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt)
20952100 * ----------
20962101 */
20972102if (SPI_exec (querystr ,0 )!= SPI_OK_SELECT )
2098- elog (ERROR ,"FOR ... EXECUTE query '%s' wasno SELECT" ,querystr );
2103+ elog (ERROR ,"FOR ... EXECUTE query '%s' wasnot SELECT" ,querystr );
20992104pfree (querystr );
21002105
21012106n = SPI_processed ;