sqlalchemy - Query a PostgreSQL view created by SQLAcodegen -


i have useful postgresql view, generated join query:

\d very_useful_view;  view "public.very_useful_view"    column    |    type     | modifiers -------------+-------------+-----------  tree_id     | dom_treeid  |  title       | text        |  grass_id    | dom_grass   |  name        | text        |  street_uuid | uuid        | 

the view modeled sqlacodegen following object:

t_very_useful_view = table(     'very_useful_view', metadata,     column('tree_id', string),     column('title', text),     column('grass_id', text),     column('name', text),     column('street_uuid', uuid) ) 

normal query works expected:

print session.query(t_very_useful_view).all() 

however, filtering -

print session.query(t_very_useful_view).\     filter(t_very_useful_view.tree_id == some_tree_id).\     all() 

raises:

attributeerror: 'table' object has no attribute 'tree_id' 

any idea missing view mapping?

the columns of table object should accessed columns property:

print session.query(t_very_useful_view).\     filter(t_very_useful_view.columns.tree_id == some_tree_id).\     all() 

this contrasts subclasses of declarative_base(), expose columns root-level object properties.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -