Thank-you for the thoughtful answers.
I have updated my C library to return the binary data correctly. I
note the restriction on not being able to retrieve different columns
in different formats.
I found that my perl DBI interface wasn't happy either with the
'escape' output format, so I changed bytea_output to 'hex', and
DBD::Pg is also happy now (I also read that the hex format is more
efficient).
--
Jason Armstrong