Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> I'm trying to write a set of C functions that mimic the COPY TO and
> COPY FROM SQL commands so I can use them to stream binary data to/
> from the client.
You cannot control the FE/BE protocol from inside a user function.
> This seems more efficient to me than passing BYTEAs back and forth.
Why? A byte is a byte. There is no possible way that you will ever
save enough microseconds from this to repay the development time you
will waste trying to kluge the system to do it.
If it's the overhead of parsing the SELECT you are unhappy with,
you could look at using the "fast path" function call protocol
to invoke your functions.
regards, tom lane