aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorTeodor Sigaev <teodor@sigaev.ru>2015-11-27 19:11:22 +0300
committerTeodor Sigaev <teodor@sigaev.ru>2015-11-27 19:11:22 +0300
commit92e38182d7c8947a4ebbc1123b44f1245e232e85 (patch)
treef01ec11404a9b554cd9dc108409701e0fc86e001 /src/backend/parser
parent0da3a9bef7ad36dc640aebf2d0482e18f21561f6 (diff)
downloadpostgresql-92e38182d7c8947a4ebbc1123b44f1245e232e85.tar.gz
postgresql-92e38182d7c8947a4ebbc1123b44f1245e232e85.zip
COPY (INSERT/UPDATE/DELETE .. RETURNING ..)
Attached is a patch for being able to do COPY (query) without a CTE. Author: Marko Tiikkaja Review: Michael Paquier
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index fba91d53ac3..7916df8b099 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -2561,9 +2561,12 @@ ClosePortalStmt:
*
* QUERY :
* COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
- * COPY ( SELECT ... ) TO file [WITH] [(options)]
+ * COPY ( query ) TO file [WITH] [(options)]
*
- * where 'file' can be one of:
+ * where 'query' can be one of:
+ * { SELECT | UPDATE | INSERT | DELETE }
+ *
+ * and 'file' can be one of:
* { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
*
* In the preferred syntax the options are comma-separated
@@ -2574,7 +2577,7 @@ ClosePortalStmt:
* COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
* [ [ USING ] DELIMITERS 'delimiter' ] ]
* [ WITH NULL AS 'null string' ]
- * This option placement is not supported with COPY (SELECT...).
+ * This option placement is not supported with COPY (query...).
*
*****************************************************************************/
@@ -2607,16 +2610,16 @@ CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
n->options = list_concat(n->options, $11);
$$ = (Node *)n;
}
- | COPY select_with_parens TO opt_program copy_file_name opt_with copy_options
+ | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
{
CopyStmt *n = makeNode(CopyStmt);
n->relation = NULL;
- n->query = $2;
+ n->query = $3;
n->attlist = NIL;
n->is_from = false;
- n->is_program = $4;
- n->filename = $5;
- n->options = $7;
+ n->is_program = $6;
+ n->filename = $7;
+ n->options = $9;
if (n->is_program && n->filename == NULL)
ereport(ERROR,