我在很多python项目中使用psycopg2,并经常使用HSTORE作为postgres数据类型。在psycopg2中,如何将register_hstore用于连接池?
通常创建我的连接如下:
connection =psycopg2.connect(...)
psycopg2.extras.register_hstore(connection)
然后允许Python dicts
和Postgres hstores
之间的无缝集成。
但是,如果我想使用连接池,显然我必须写:
pool = psycopg2.pool.SimpleConnectionPool(...)
,然后用
connectionFromPool = pool.getconn()
使用它,但如果运行register_hstore(connectionFromPool)
每次我问它的时候,那么该函数将在同一连接上被多次调用。这会导致副作用吗?连接池不是为了避免不必要的呼叫吗?
当最初创建连接时,是否有某种方式告诉SimpleConnectionPool
使用register_hstore
?