MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.88k stars 399 forks source link

allow setting statement name in `set_type_codec` #1131

Closed CobaltCause closed 4 months ago

CobaltCause commented 6 months ago

This is necessary when using PgBouncer because otherwise the default simplistically-generated statement names can fight with other programs using asyncpg due to PgBouncer sharing the same underlying PostgreSQL connection and thus the prepared statement names.

Supposedly asyncpg can be made to use an unnamed statement here by turning the cache off, but I can't for the life of me figure out how to do that when using asyncpg through SQLAlchemy; I observe that setting prepared_statement_cache_size to 0 as described here doesn't cause use_cache to be False. Anyway, that's not really asyncpg's problem.

I think this functionality should probably be provided either way since it'd be kinda weird to only allow configuring the names of some prepared statements.

CobaltCause commented 4 months ago

Closing this since it's been a while and I've since solved my problem by using psycopg3 instead, which supports disabling prepared statements altogether.