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

后端 未结 7 690
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  野性不改
    2021-02-01 01:58

    Just

    >>> q[0].keys()
    

    After

    row_data = session.query(Projects).filter_by(id=1).one()
    

    Example :

    >>> q = session.query(users_user.phone,users_user.first_name).filter(users_user.phone=='79267548577').limit(1).all()
    >>> columns_names = q[0].keys
    

    Result :

    >>> q[0].keys()
    ['phone', 'first_name']
    >>> 
    

提交回复
热议问题