diff options
Diffstat (limited to 'src/test/regress/expected/transactions.out')
-rw-r--r-- | src/test/regress/expected/transactions.out | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/test/regress/expected/transactions.out b/src/test/regress/expected/transactions.out index 955558d690b..1c8ba64c5c0 100644 --- a/src/test/regress/expected/transactions.out +++ b/src/test/regress/expected/transactions.out @@ -374,6 +374,84 @@ ERROR: portal "c" cannot be run FETCH 10 FROM c; ERROR: portal "c" cannot be run COMMIT; +-- +-- Check that "stable" functions are really stable. They should not be +-- able to see the partial results of the calling query. (Ideally we would +-- also check that they don't see commits of concurrent transactions, but +-- that's a mite hard to do within the limitations of pg_regress.) +-- +select * from xacttest; + a | b +-----+--------- + 56 | 7.8 + 100 | 99.097 + 0 | 0.09561 + 42 | 324.78 + 777 | 777.777 +(5 rows) + +create or replace function max_xacttest() returns smallint language sql as +'select max(a) from xacttest' stable; +begin; +update xacttest set a = max_xacttest() + 10 where a > 0; +select * from xacttest; + a | b +-----+--------- + 0 | 0.09561 + 787 | 7.8 + 787 | 99.097 + 787 | 324.78 + 787 | 777.777 +(5 rows) + +rollback; +-- But a volatile function can see the partial results of the calling query +create or replace function max_xacttest() returns smallint language sql as +'select max(a) from xacttest' volatile; +begin; +update xacttest set a = max_xacttest() + 10 where a > 0; +select * from xacttest; + a | b +-----+--------- + 0 | 0.09561 + 787 | 7.8 + 797 | 99.097 + 807 | 324.78 + 817 | 777.777 +(5 rows) + +rollback; +-- Now the same test with plpgsql (since it depends on SPI which is different) +create or replace function max_xacttest() returns smallint language plpgsql as +'begin return max(a) from xacttest; end' stable; +begin; +update xacttest set a = max_xacttest() + 10 where a > 0; +select * from xacttest; + a | b +-----+--------- + 0 | 0.09561 + 787 | 7.8 + 787 | 99.097 + 787 | 324.78 + 787 | 777.777 +(5 rows) + +rollback; +create or replace function max_xacttest() returns smallint language plpgsql as +'begin return max(a) from xacttest; end' volatile; +begin; +update xacttest set a = max_xacttest() + 10 where a > 0; +select * from xacttest; + a | b +-----+--------- + 0 | 0.09561 + 787 | 7.8 + 797 | 99.097 + 807 | 324.78 + 817 | 777.777 +(5 rows) + +rollback; -- test case for problems with dropping an open relation during abort BEGIN; savepoint x; |