Throw suitable error for COPY TO STDOUT/FROM STDIN in a SQL function.
Throw suitable error for COPY TO STDOUT/FROM STDIN in a SQL function.

A client copy can't work inside a function because the FE/BE wire protocol
doesn't support nesting of a COPY operation within query results.  (Maybe
it could, but the protocol spec doesn't suggest that clients should support
this, and libpq for one certainly doesn't.)

In most PLs, this prohibition is enforced by spi.c, but SQL functions don't
use SPI.  A comparison of _SPI_execute_plan() and init_execution_state()
shows that rejecting client COPY is the only discrepancy in what they
allow, so there's no other similar bugs.

This is an astonishingly ancient oversight, so back-patch to all supported
branches.

Report: da1a3fe13a2b7eb4fd12c66ac6fcd77e8c29c23c@BY2PR05MB2309.namprd05.prod.outlook.com

lisakowen/gpdb,adam8157/gpdb,lisakowen/gpdb,50wu/gpdb,adam8157/gpdb,lisakowen/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,xinzweb/gpdb,xinzweb/gpdb,50wu/gpdb,adam8157/gpdb,greenplum-db/gpdb,50wu/gpdb,adam8157/gpdb,greenplum-db/gpdb,lisakowen/gpdb,lisakowen/gpdb,xinzweb/gpdb,50wu/gpdb,lisakowen/gpdb,adam8157/gpdb,xinzweb/gpdb,greenplum-db/gpdb,xinzweb/gpdb,50wu/gpdb,xinzweb/gpdb,50wu/gpdb,50wu/gpdb,xinzweb/gpdb,greenplum-db/gpdb,adam8157/gpdb,lisakowen/gpdb,adam8157/gpdb,adam8157/gpdb,lisakowen/gpdb,50wu/gpdb,greenplum-db/gpdb,xinzweb/gpdb,greenplum-db/gpdb