2. The general difficulty of getting psql var values into a DO block (currently I use temp tables).
Maybe this means that DO should be extended in some way to allow for parameters, at least when PL/pgSQL is used?
I agree with this wholeheartedly. ISTM most of this thread is about limitations of our current DO implementation, partially addressed by adding a bunch of scripting commands, specific to psql. I don't think that's the right solution.
This proposal is not against to DO parametrization. It is same like conditional block in C (#ifdef). There is similarity with C statements - and both has sense.
Pavel
regards
-- Tomas Vondra http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services