6

Usually I connect/query like this

class MyTable(Base):
    __tablename__ = 'mytable'
    __table_args__ = {'schema': 'tables'}

    id = Column(Integer, primary_key=True)
    salutation = Column(VARCHAR(1))

def __init__(self, salutation):
    self.salutation = salutation

def load():
    """"""
    Session = sessionmaker(bind=engine)
    session = Session()
    for i in session.query(MyTable).order_by(MyTable.id):
        entries.append(i.__dict__)
    session.close()

But How I query an (PostgreSQL) DB View, without any keys?

user966660
  • 634
  • 1
  • 8
  • 20
  • 2
    Read [Reflecting Views](http://docs.sqlalchemy.org/en/rel_1_0/core/reflection.html#reflecting-views) section of documentation. You do need to have a `primary_key`, which you can *fake* - just add `primary_key = True` to the columns, a combination of which will uniquely identify rows in the view. – van Sep 28 '15 at 00:15
  • 1
    In addiiton to @van's comment, see the two answers to [this question](https://stackoverflow.com/questions/20518521/is-possible-to-mapping-view-with-class-using-mapper-in-sqlalchemy) if you want to use ORM, which show different ways to get mapped classes. – stephan Sep 28 '15 at 04:46

0 Answers0