What are the use cases for acquiring a connection from a pool and then calling execute on the connection rather than calling execute on a pool object directly?
In the docs for the Pool class, this example is shown:
con = await pool.acquire()
try:
await con.execute(...)
finally:
await pool.release(con)
A connection is acquired from the pool and used to execute a statement. What is the benefit of doing that over just calling the execute method directly on the Pool object such as the below?
async with asyncpg.create_pool(user=pg_user,
password=pg_pass,
host=pg_host,
port=pg_port,
database=pg_db,
command_timeout=60) as pool:
pool.execute(f'TRUNCATE TABLE {table};')
The docs for Pool.execute even state the following:
Execute an SQL command (or commands).
Pool performs this operation using one of its connections. Other than that, it behaves identically to Connection.execute().