aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/analyze.c15
-rw-r--r--src/backend/parser/gram.y23
2 files changed, 34 insertions, 4 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index ae3469c86c7..23e956798d6 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.348 2006/08/25 04:06:51 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.349 2006/08/30 23:34:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -341,6 +341,19 @@ transformStmt(ParseState *pstate, Node *parseTree,
}
break;
+ case T_CopyStmt:
+ {
+ CopyStmt *n = (CopyStmt *) parseTree;
+
+ result = makeNode(Query);
+ result->commandType = CMD_UTILITY;
+ if (n->query)
+ n->query = transformStmt(pstate, (Node *) n->query,
+ extras_before, extras_after);
+ result->utilityStmt = (Node *) parseTree;
+ }
+ break;
+
case T_AlterTableStmt:
result = transformAlterTableStmt(pstate,
(AlterTableStmt *) parseTree,
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index a77e73a43fc..4a0ce515b8a 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.558 2006/08/25 04:06:51 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.559 2006/08/30 23:34:21 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -1614,11 +1614,15 @@ ClosePortalStmt:
/*****************************************************************************
*
* QUERY :
- * COPY <relname> ['(' columnList ')'] FROM/TO [WITH options]
+ * COPY relname ['(' columnList ')'] FROM/TO file [WITH options]
*
* BINARY, OIDS, and DELIMITERS kept in old locations
* for backward compatibility. 2002-06-18
*
+ * COPY ( SELECT ... ) TO file [WITH options]
+ * This form doesn't have the backwards-compatible option
+ * syntax.
+ *
*****************************************************************************/
CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
@@ -1626,6 +1630,7 @@ CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
{
CopyStmt *n = makeNode(CopyStmt);
n->relation = $3;
+ n->query = NULL;
n->attlist = $4;
n->is_from = $6;
n->filename = $7;
@@ -1642,6 +1647,18 @@ CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
n->options = list_concat(n->options, $10);
$$ = (Node *)n;
}
+ | COPY select_with_parens TO copy_file_name opt_with
+ copy_opt_list
+ {
+ CopyStmt *n = makeNode(CopyStmt);
+ n->relation = NULL;
+ n->query = (Query *) $2;
+ n->attlist = NIL;
+ n->is_from = false;
+ n->filename = $4;
+ n->options = $6;
+ $$ = (Node *)n;
+ }
;
copy_from:
@@ -1652,7 +1669,7 @@ copy_from:
/*
* copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
* used depends on the direction. (It really doesn't make sense to copy from
- * stdout. We silently correct the "typo". - AY 9/94
+ * stdout. We silently correct the "typo".) - AY 9/94
*/
copy_file_name:
Sconst { $$ = $1; }