Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLAlchemy column name with space

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')   < -- I want to do that
...

There is for sure a simple way of doing that, but I can't seem to find it anywhere.

like image 733
Hans Daigle Avatar asked Dec 23 '22 12:12

Hans Daigle


1 Answers

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)
like image 184
Nilav Baran Ghosh Avatar answered Dec 28 '22 05:12

Nilav Baran Ghosh