I am uploading images/zip files from client application via Java/JDBC to a bytea (NOT BLOB) column. But need to be able to export them to server side files. Postgres 13.
In plpgsql function I have:
EXECUTE format ('COPY (SELECT zipfile FROM file_upload) TO %L (FORMAT binary)', l_file_name);
But the first line is 'PGCOPY'. The copy command says there is no header for BINARY but there is :(
This has the same result:
COPY (SELECT zipfile FROM file_upload) TO PROGRAM 'cat > /tmp/dunc ' (FORMAT binary);
This seems a common requirement, but I can't find a simple resolution.
Similar to How to export binary file with psql (without PGCOPY header)? but from within a (privileged) database function