]> granicus.if.org Git - postgresql/commitdiff
exec_eval_simple_expr() needs to do CommandCounterIncrement() not just
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 21 Dec 2004 18:33:36 +0000 (18:33 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 21 Dec 2004 18:33:36 +0000 (18:33 +0000)
GetTransactionSnapshot() to ensure ActiveSnapshot advances properly.
Sigh.  Extend regression test so it reveals this error too.

src/pl/plpgsql/src/pl_exec.c
src/test/regress/expected/plpgsql.out
src/test/regress/sql/plpgsql.sql

index 5366cd1acf279e2fc0ab24b0aea97764d950a9fb..90dfc3c0d14ed78a38253ff37477855b13c55af8 100644 (file)
@@ -3,7 +3,7 @@
  *                       procedural language
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.125 2004/12/19 20:20:17 tgl Exp $
+ *       $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.126 2004/12/21 18:33:35 tgl Exp $
  *
  *       This software is copyrighted by Jan Wieck - Hamburg.
  *
@@ -3631,7 +3631,7 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
 
        /*
         * We have to do some of the things SPI_execute_plan would do,
-        * in particular adjust ActiveSnapshot if we are in a non-read-only
+        * in particular advance the snapshot if we are in a non-read-only
         * function.  Without this, stable functions within the expression
         * would fail to see updates made so far by our own function.
         */
@@ -3644,7 +3644,11 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
 
                oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
                if (!estate->readonly_func)
+               {
+                       CommandCounterIncrement();
                        ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
+               }
+
                /*
                 * Finally we can call the executor to evaluate the expression
                 */
index 1f11bbb75c92d843e06f96dbe8afb4b6ba0b08c9..10df82cfc2463cc7f79fe49e506656e67bc3394e 100644 (file)
@@ -2089,5 +2089,17 @@ select sp_add_user('user2');
           -1
 (1 row)
 
+select sp_add_user('user3');
+ sp_add_user 
+-------------
+           3
+(1 row)
+
+select sp_add_user('user3');
+ sp_add_user 
+-------------
+          -1
+(1 row)
+
 drop function sp_add_user(text);
 drop function sp_id_user(text);
index 48618b95085cb2739f3adc4da9117fabbc76f67e..62aa3543479629302deed5620683af5162ef3923 100644 (file)
@@ -1802,6 +1802,8 @@ end$$ language plpgsql;
 select sp_add_user('user1');
 select sp_add_user('user2');
 select sp_add_user('user2');
+select sp_add_user('user3');
+select sp_add_user('user3');
 
 drop function sp_add_user(text);
 drop function sp_id_user(text);