Here is a rebase. I made some tests use actual expressions instead of just 0 and 1. No other changes.
Sigh. Better with the attachment. Sorry for the noise.
Here is a very minor rebase.
I'm a smidge worried about this. It seems like psql is growing a scripting language. Do we want to go our own way with a kind of organically grown scripting system? Or should we be looking at embedding client-side scripting in a more structured, formal way instead? Embed a lua interpreter or something?