diff --git a/src/Rel8/Query/Materialize.hs b/src/Rel8/Query/Materialize.hs index 64502711..a091c2f2 100644 --- a/src/Rel8/Query/Materialize.hs +++ b/src/Rel8/Query/Materialize.hs @@ -15,7 +15,6 @@ import Opaleye.With ( withMaterializedExplicit ) import Rel8.Expr ( Expr ) import Rel8.Query ( Query ) import Rel8.Query.Opaleye ( fromOpaleye, toOpaleye ) -import Rel8.Query.Rebind ( rebind ) import Rel8.Table ( Table ) import Rel8.Table.Opaleye ( unpackspec ) @@ -31,10 +30,9 @@ import Rel8.Table.Opaleye ( unpackspec ) -- specifically the @WITH _ AS MATERIALIZED (_)@ form introduced in PostgreSQL -- 12. This means that 'materialize' can only be used with PostgreSQL 12 or -- newer. -materialize :: (Table Expr a, Table Expr b) - => Query a -> (Query a -> Query b) -> Query b +materialize :: Table Expr a => Query a -> (Query a -> Query b) -> Query b materialize query f = - (>>= rebind "with") . fromOpaleye $ + fromOpaleye $ withMaterializedExplicit unpackspec (toOpaleye query') (toOpaleye . f . fromOpaleye) diff --git a/src/Rel8/Tabulate.hs b/src/Rel8/Tabulate.hs index a6f26fd0..8ecc0fd5 100644 --- a/src/Rel8/Tabulate.hs +++ b/src/Rel8/Tabulate.hs @@ -628,7 +628,7 @@ difference a b = a <* absent b -- | 'Q.materialize' for 'Tabulation's. -materialize :: (Table Expr k, Table Expr a, Table Expr b) +materialize :: (Table Expr k, Table Expr a) => Tabulation k a -> (Tabulation k a -> Query b) -> Query b materialize tabulation f = case peek tabulation of Tabulation query -> do