0

The answer for another post says how to create a view. But all fields are generated dynamically:

class MyView(Base):
    __table__ = view

And after we query it as below:

engine.execute(select([func.count('*')], from_obj=MyView)).scalar()

Is it possible to declare a view fields obviously? To I could query it as other entities:

my_views = MyView.query().all()
print(my_views[0].some_field)
Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
  • 1
    Have a look here: https://github.com/sqlalchemy/sqlalchemy/wiki/Views, if you want to define and create views from Python. If on the other hand you want to map an existing view, and define its columns explicitly in the mapping, just do so. A view is a relation just like a table is. – Ilja Everilä Oct 16 '19 at 09:36
  • @IljaEverilä, thank you very much. It is that I wanted. – Denis Sologub Oct 16 '19 at 10:08

0 Answers0