SQLAlchemy column name with space

后端 未结 1 883
南笙
南笙 2020-12-11 23:39

I\'m trying to filter a table on a column that contain spaces.

...
events = database_session.query(table)
events.filter(table.column with space == \'xvalue\'         


        
相关标签:
1条回答
  • 2020-12-12 00:14

    There are two ways to resolve this.

    1. When defining the table you would need to specify an alias with the key parameter
    t_table_name = Table(
        'tablename',
        metadata,
        Column('SQL Column', Integer, key='sql_column')
    )
    
    1. Define the ORM class as
    class Employee(Base):
        emp_name = Column("employee name", String)
    
    0 讨论(0)
提交回复
热议问题