Re: Multiple result sets - Mailing list pgsql-general

From Clodoaldo
Subject Re: Multiple result sets
Date
Msg-id a595de7a0806011312m52b0fd35rd1d6e758df55458@mail.gmail.com
Whole thread Raw
In response to Multiple result sets  (Clodoaldo <clodoaldo.pinto.neto@gmail.com>)
Responses Re: Multiple result sets  ("Adam Rich" <adam.r@sbcglobal.net>)
Re: Multiple result sets  (joe@omc-international.com.au)
List pgsql-general
2008/6/1 Adam Rich <adam.r@sbcglobal.net>:
>
>> I need that 5 queries, fired from the same ajax request to a web
>> python application, see the same database snapshot. The driver is
>> psycopg2.
>>
>> Since postgresql 8.2 functions can't return multiple result sets what
>> would be the best aproach?
>>
>
> You want to set your transaction isolation to "Serializable".
> Then execute your 5 queries via the same connection, and the same
> Transaction.
>
> You can do that with this command:
>
> BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;

I'm not sure i got it. You mean like this?:

import psycopg2 as db
dsn = 'host=localhost dbname=dbname user=user password=passwd'
connection = db.connect(dsn)
cursor = connection.cursor()

cursor.execute('BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;');
rs1 = cursor.execute(query_1, (param1,))
rs2 = cursor.execute(query_2, (param2,))
cursor.execute('commit;');

cursor.close()
connection.close()

I tested it and it raises no exception. I just don't understand if a
transaction persists between execute() calls.

Regards, Clodoaldo

pgsql-general by date:

Previous
From: "Adam Rich"
Date:
Subject: Re: Multiple result sets
Next
From: "Adam Rich"
Date:
Subject: Re: Multiple result sets