ST_SummaryStats() returns a record , so instead of using SELECT as the expression (which will return record ), use it as a FROM and select the desired statistics in SELECT , so it becomes very simple:
SELECT filename, count, sum, mean, stddev, min, max FROM tiles, ST_SummaryStats(tiles.rast, 1, true);
This leads to the so-called LATERAL JOIN , and since ST_SummaryStats() returns only one row for the specified raster in tiles , you do not need a join condition, filter, or anything else.
I'm not sure about the ability of SQLAlchemy to use the result of a function as a class, but the surefire way to do this is to wrap the SELECT in VIEW above and then access the view from SQLAlchemy:
CREATE VIEW raster_stats AS SELECT filename, count, sum, mean, stddev, min, max FROM tiles, ST_SummaryStats(tiles.rast, 1, true);
source share