]> granicus.if.org Git - postgresql/commitdiff
Ensure that a plpgsql LOOP with an empty body still executes at least
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 24 Oct 2005 15:10:22 +0000 (15:10 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 24 Oct 2005 15:10:22 +0000 (15:10 +0000)
one CHECK_FOR_INTERRUPTS() call, so that you can control-C out of the
loop.  Reported by Merlin Moncure.

src/pl/plpgsql/src/pl_exec.c

index 721b1014fdc65c7c4afa4017ed8342b22726205c..df82dd3dc1b4e1eb98bcfe789820a4bf3fcf4bfe 100644 (file)
@@ -3,7 +3,7 @@
  *                       procedural language
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.153 2005/10/15 02:49:49 momjian Exp $
+ *       $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.154 2005/10/24 15:10:22 tgl Exp $
  *
  *       This software is copyrighted by Jan Wieck - Hamburg.
  *
@@ -974,6 +974,17 @@ exec_stmts(PLpgSQL_execstate * estate, List *stmts)
 {
        ListCell   *s;
 
+       if (stmts == NIL)
+       {
+               /*
+                * Ensure we do a CHECK_FOR_INTERRUPTS() even though there is no
+                * statement.  This prevents hangup in a tight loop if, for instance,
+                * there is a LOOP construct with an empty body.
+                */
+               CHECK_FOR_INTERRUPTS();
+               return PLPGSQL_RC_OK;
+       }
+
        foreach(s, stmts)
        {
                PLpgSQL_stmt *stmt = (PLpgSQL_stmt *) lfirst(s);