aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-01-14 13:27:47 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2017-01-14 13:27:47 -0500
commit47d32a464a8a5e70c95fe52d6b3e3a3fb25fd845 (patch)
treed60792f020d3368591d51d85e94586b5f2591b03
parent4779d6ca20f7ce89c61b7729a6c714a258586d75 (diff)
downloadpostgresql-47d32a464a8a5e70c95fe52d6b3e3a3fb25fd845.tar.gz
postgresql-47d32a464a8a5e70c95fe52d6b3e3a3fb25fd845.zip
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
-rw-r--r--src/backend/executor/functions.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c
index ae17ea7722c..3368792cf8f 100644
--- a/src/backend/executor/functions.c
+++ b/src/backend/executor/functions.c
@@ -498,7 +498,16 @@ init_execution_state(List *queryTree_list,
else
stmt = (Node *) pg_plan_query(queryTree, 0, NULL);
- /* Precheck all commands for validity in a function */
+ /*
+ * Precheck all commands for validity in a function. This should
+ * generally match the restrictions spi.c applies.
+ */
+ if (IsA(stmt, CopyStmt) &&
+ ((CopyStmt *) stmt)->filename == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot COPY to/from client in a SQL function")));
+
if (IsA(stmt, TransactionStmt))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),