例如,当我执行以下代码时,结果数据类型为str:
result = engine.execute(’’‘ 选择CAST(’{“foo”:“bar”}‘作为JSON)为json’’’)row = result.fetchone()json = row [0]类型(…
json
你至少可以明确地实现它 告诉SQLAlchemy结果是JSON :
from sqlalchemy.types import JSON stmt = text('''SELECT CAST('{"foo": "bar"}' as JSON) as `json`''') stmt = stmt.columns(json=JSON) row = engine.execute(stmt).fetchone() type(row.json)