Matt Wilson <[EMAIL PROTECTED]> writes:

> On Wed, Sep 01, 2004 at 02:46:39PM +0100, Christian Smith wrote:
>> 
>> Add a new "BEGIN [TRANSACTION] FOR READONLY" statement, which begins the
>> transaction with a read lock only and doesn't allow the transaction to
>> even try to promote to a write lock.
>
> Why do you need a transaction at all if you're not going to commit?

If you want to do a series of queries where you require consistent database
state, a transaction allows you to do that.  For example:

Time    Process 1                                     Process 2
---------------------------------------------------------------
 1      INSERT INTO t1
          VALUES (1, 'one');
        
 2      INSERT INTO t2
          VALUES ('hello', 'world');
        
 3                                                    SELECT * FROM t2;
        
 4      INSERT INTO t1
          VALUES (2, 'two');
        
 5                                                    SELECT * FROM t1;
       

yields different results than


Time    Process 1                                     Process 2
---------------------------------------------------------------
 1      INSERT INTO t1
          VALUES (1, 'one');

 2      INSERT INTO t2
          VALUES ('hello', 'world');

 3                                                    BEGIN;
                                                      SELECT * FROM t2;

 4      INSERT INTO t1
          VALUES (2, 'two');

 5                                                    SELECT * FROM t1;
                                                      END TRANSACTION;


In the latter case, you get the state of t2 and t1 as of time 3, whereas in
the former case, you get the state of the two tables at times 3 and 5,
respectively.

Derrell

Reply via email to