What is the way to select a hard-coded value in a query?
python, sqlalchemy
Solution
Use the `literal` construct.
from sqlalchemy import literal
result = session.query(
table_a.c.col1, table_a.c.col2, literal('hardcoded value').label('col3')
)
Problem
I have a SQL query that uses a hard-coded value: ``` select col1, col2, 'some hard coded value' as col2 from table_a union all select col1, col2, col3 from table_b ``` I tried the following in SQLAlchemy: ``` result = session.query(table_a.col1, table_a.col2, 'hardcoded value'.label('col3') ``` but got an `AttributeError`, which makes sense. I also thought about adding the value in Python then doing the union. How can I add this hard coded value to a SQLAlchemy query?