【发布时间】:2021-11-28 02:15:03
【问题描述】:
我正在使用异步引擎。当我尝试执行任何操作时:
async with self.async_engine.connect() as con:
query = "SELECT id, name FROM item LIMIT 50;"
result = await con.execute(f"{query}")
我明白了:
Exception has occurred: ObjectNotExecutableError
Not an executable object: 'SELECT id, name FROM item LIMIT 50;'
这个问题之前是用户@stilmaniac 提出的,但现在是deleted from SO。
我在 Google 搜索缓存中找到了它,here is copy。
我有同样的问题,所以我重新问一下,但原始版本如下:
我正在尝试从元数据创建表,如下所示:
Base = declarative_base()
properties = Table(
'properties', Base.metadata,
# ...
Column('geolocation', Geography(geometry_type='POINT', srid=4326)),
# ...
)
engine = create_async_engine("postgresql+asyncpg://user:password@postgres/")
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
给我以下错误:
sqlalchemy.exc.ObjectNotExecutableError: Not an executable object: 'CREATE INDEX "idx_properties_geolocation" ON "properties" USING GIST ("geolocation")'
考虑到这个doc
版本:
- 操作系统:macOS 11.4 ARM
- SQLAlchemy:1.4.22
- Python:3.6
【问题讨论】:
-
你试过不使用 f 字符串吗?
-
@ReedJones
f"{}"给出与str()相同的结果,这不是原因。
标签: python python-3.x sqlalchemy python-asyncio asyncpg