python - What is the way to select a hard-coded value in a query? -
i have sql query uses hard-coded value:
select col1, col2, 'some hard coded value' col2 table_a union select col1, col2, col3 table_b
i tried following in sqlalchemy:
result = session.query(table_a.col1, table_a.col2, 'hardcoded value'.label('col3')
but got attributeerror
, makes sense. thought adding value in python doing union.
how can add hard coded value sqlalchemy query?
use literal
construct.
from sqlalchemy import literal result = session.query( table_a.c.col1, table_a.c.col2, literal('hardcoded value').label('col3') )
Comments
Post a Comment