>
> I think it'd be a lot better to expose the script status to psql.
> (without having to write "foo; echo status=$?").
>
I agree, and I hacked up a proof of concept, but started another thread at
https://www.postgresql.org/message-id/CADkLM=cWao2x2f+UDw15W1JkVFr_bsxfstw=NGea7r9m4j-7rQ@mail.gmail.com
so as not to clutter up this one.