postgresqlpsycopg2python-asyncioaiopg

aiopg/psycopg2 autocommit and transactions


My doubt is very SQLish but

Since psycopg2 async connections are autocommit, I'm manually setting up transactions defined and then closed in the same cursor/connection.

like this:

async def transaction(self, queries):
    async with aiopg.create_pool(connection) as pool:
        async with pool.acquire() as conn:
            async with conn.cursor() as cur:
                await cur.execute('BEGIN transaction;')
                for query in queries:
                    await cur.execute(query)
                await cur.execute('COMMIT transaction;')

My doubt is since its completly asynchronous, if there is a rollback will other commands that have been processed in the same timespan be also rolledback or will thy be rolled back connection based?

Thanks!!


Solution

  • The rollback is connection-based.