SQLAlchemy - mapping result from postgres function

Viewed 49

I've plpgsql function returning SETOF mytype, where mytype user defined type (set of columns). I'd like to map result of this function to sqlalchemy object like this:

stmt = text("SELECT col1, col2, col3 FROM myfunc(:name)")
stmt = stmt.columns(MyType.col1, MyType.col2, MyType.col3)
session.query(MyType).from_statement(stmt).params(page=1).all()

The question is how to define MyType in SQLAlchemy without defining table or view in database.

0 Answers
Related