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

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -