How to get column names from SQLAlchemy result (declarative syntax)

后端 未结 7 701
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 01:26

I am working in a pyramid project and I\'ve the table in SQLAlchemy in declarative syntax

\"\"\"models.py\"\"\"
class Projects(Base):
    __tablename__ = \'proje         


        
7条回答
  •  Happy的楠姐
    2021-02-01 01:56

    The difference is between ORM and non-ORM, not declarative, which is just a helper for the ORM.

    Query has a method column_descriptions() that was added for this purpose::

    http://www.sqlalchemy.org/docs/orm/query.html#sqlalchemy.orm.query.Query.column_descriptions

    the example there seems like it has a typo, says q.columns but it should be q.column_descriptions (edit: just fixed it).

提交回复
热议问题