The SQL standard overloads WITH in a query to supply not only CTEs
but also lexically-scoped option settings:
WITH XMLBINARY BASE64, foo(bar) AS (VALUES('\xDEADBEEF'::bytea))
SELECT XMLELEMENT(name foo, XMLATTRIBUTES(bar)) FROM foo;
PG already implements XMLBINARY and XMLOPTION using the GUC system.
Would it be easy or hard, reasonable or objectionable, to generalize
PG's WITH syntax along these lines, rewriting it into lexically-scoped
settings of GUCs?
Perhaps a further development in the same line would be enabling the planner
to choose among IMMUTABLE specializations of a function, as well as a
generic STABLE version that depends on a GUC.
-Chap