AS rast FROM triangle, hapctnpp_geotiff WHERE ST_Intersects(triangle.the_geom,rast) LIMIT 1) SELECT (ST_SummaryStats(ST_Union(ST_MapAlgebraExpr(m. rast, f.rast, '[rast1.val]', '16BUI')))).* as rast FROM hapctnpp_geotiff m JOIN foo f ON ST_Intersects(m.rast, f.rast);