Throw suitable error for COPY TO STDOUT/FROM STDIN in a SQL function.
authorTom Lane
Sat, 14 Jan 2017 18:27:47 +0000 (13:27 -0500)
committerTom Lane
Sat, 14 Jan 2017 18:27:47 +0000 (13:27 -0500)
commita23ea8f65e07aa56a501bbdd68068b52469d77cf
treea1dc1ecd82ec7c00fc7e63c2bbf9123c50f42866
parent7fbd3ddd1d2b76c0229cdc44d355b6238c146335
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: https://postgr.es/m/BY2PR05MB2309EABA3DEFA0143F50F0D593780@BY2PR05MB2309.namprd05.prod.outlook.com
src/backend/executor/functions.c