The main reason I wasn't happy with this before is that there was nothing stopping you from writing materialize query pure. This returned query would produce invalid SQL if you actually tried to use it, because it would attempt to reference a common table expression outside the scope of the WITH statement.
The "solution" here is just to throw a rebind around the result such that materialize incurs an extra Table Expr b constraint, which means that you can't return Query (Query a) because Query a can't satisfy a Table Expr constraint.
The main reason I wasn't happy with this before is that there was nothing stopping you from writing
materialize query pure
. This returned query would produce invalid SQL if you actually tried to use it, because it would attempt to reference a common table expression outside the scope of theWITH
statement.The "solution" here is just to throw a
rebind
around the result such thatmaterialize
incurs an extraTable Expr b
constraint, which means that you can't returnQuery (Query a)
becauseQuery a
can't satisfy aTable Expr
constraint.