首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >asyncpg.exceptions.DuplicatePreparedStatementError:预准备语句"stmt_5“已存在

asyncpg.exceptions.DuplicatePreparedStatementError:预准备语句"stmt_5“已存在
EN

Stack Overflow用户
提问于 2017-03-22 18:43:56
回答 1查看 464关注 0票数 0

函数"runquery“从程序的不同部分被调用。在这种情况下,我从不在查询语句中使用"prepare“。我已经阅读了所有其他关于“准备好的语句已经存在”的问题,并且也尝试了"DEALLOCATE ALL“。但这会导致相反的错误:当下面的错误报告预准备的语句已经存在时,DEALLOCATE ALL会导致报告它不存在。

这是我第一次尝试使用asyncpg运行这种类型的程序。我之前在使用psycopg2时没有这个功能。我应该回到psycopg2吗?

经过如下所示的多次查询后,runquery以错误报告结束:

代码语言:javascript
复制
Could not complete query "select uuid from wos_2017_1.combined_name   where  combined_name = 'xxxxxxx';"  
Traceback (most recent call last):
  File "update2017.py", line 1206, in runquery
    result = await con.fetch(query)
  File "/usr/lib/python3/dist-packages/asyncpg/connection.py", line 268, in fetch
    stmt = await self._get_statement(query, timeout)
  File "/usr/lib/python3/dist-packages/asyncpg/connection.py", line 212, in _get_statement
    state = await protocol.prepare(None, query, timeout)
  File "asyncpg/protocol/protocol.pyx", line 140, in prepare      (asyncpg/protocol/protocol.c:55210)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result() 
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
asyncpg.exceptions.DuplicatePreparedStatementError: prepared statement "stmt_7" already exists

$ grep -c  INSERT /tmp/y.log
1006
$ grep -c  SELECT /tmp/y.log
1364
$ grep -ci  UPDATE /tmp/y.log
1044
$ grep -ci  delete /tmp/y.log
2548



    import asyncio,asyncpg

    async def make_pool():
         """Create asyncpg connection pool to database"""

         pool = await asyncpg.create_pool(database='wos',
                                 host = 'localhost',
                                 user = 'xx',
                                 password='xxxxxx',


                     port=5432,
                                 min_size=10,
                                 max_size=50)

         return pool

    async def get_con(pool):
        con = await pool.acquire()
        return con

    async def runquery(query):
        con = await get_con(pool)
        try:
            if query.startswith('delete from') or query.startswith('insert'):
                result = await con.execute(query)
            else:
                result = await con.fetch(query)
        except:
            print('Could not complete query "{}"'.format(query))
            print(traceback.format_exc())
            result = None
            exit(1)
        finally:
            await pool.release(con)
        return result, success
EN

回答 1

Stack Overflow用户

发布于 2017-04-05 23:13:58

这看起来像是asyncpg中的一个bug。请向https://github.com/MagicStack/asyncpg/issues报告,您将在那里获得帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42949295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档