aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2004-01-05 20:58:58 +0000
committerNeil Conway <neilc@samurai.com>2004-01-05 20:58:58 +0000
commit5d472f64647346a44af6ab2ab9ca70cadf9fe788 (patch)
tree8799de9c7331e987cae127009414207af3b35dd4 /src
parent71998c1e51f62cea8d0ef15047315300240d1a2e (diff)
downloadpostgresql-5d472f64647346a44af6ab2ab9ca70cadf9fe788.tar.gz
postgresql-5d472f64647346a44af6ab2ab9ca70cadf9fe788.zip
Trivial refactoring: move analysis of ViewStmt into its own function for
readability and for the sake of consistency with the rest of analyze.c
Diffstat (limited to 'src')
-rw-r--r--src/backend/parser/analyze.c102
1 files changed, 56 insertions, 46 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 061372f39f0..a97606b05d3 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.292 2003/11/29 19:51:51 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.293 2004/01/05 20:58:58 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -95,6 +95,8 @@ typedef struct
static List *do_parse_analyze(Node *parseTree, ParseState *pstate);
static Query *transformStmt(ParseState *pstate, Node *stmt,
List **extras_before, List **extras_after);
+static Query *transformViewStmt(ParseState *pstate, ViewStmt *stmt,
+ List **extras_before, List **extras_after);
static Query *transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt);
static Query *transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
List **extras_before, List **extras_after);
@@ -322,51 +324,8 @@ transformStmt(ParseState *pstate, Node *parseTree,
break;
case T_ViewStmt:
- {
- ViewStmt *n = (ViewStmt *) parseTree;
-
- n->query = transformStmt(pstate, (Node *) n->query,
- extras_before, extras_after);
-
- /*
- * If a list of column names was given, run through and
- * insert these into the actual query tree. - thomas
- * 2000-03-08
- *
- * Outer loop is over targetlist to make it easier to skip
- * junk targetlist entries.
- */
- if (n->aliases != NIL)
- {
- List *aliaslist = n->aliases;
- List *targetList;
-
- foreach(targetList, n->query->targetList)
- {
- TargetEntry *te = (TargetEntry *) lfirst(targetList);
- Resdom *rd;
-
- Assert(IsA(te, TargetEntry));
- rd = te->resdom;
- Assert(IsA(rd, Resdom));
- /* junk columns don't get aliases */
- if (rd->resjunk)
- continue;
- rd->resname = pstrdup(strVal(lfirst(aliaslist)));
- aliaslist = lnext(aliaslist);
- if (aliaslist == NIL)
- break; /* done assigning aliases */
- }
-
- if (aliaslist != NIL)
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("CREATE VIEW specifies more column names than columns")));
- }
- result = makeNode(Query);
- result->commandType = CMD_UTILITY;
- result->utilityStmt = (Node *) n;
- }
+ result = transformViewStmt(pstate, (ViewStmt *) parseTree,
+ extras_before, extras_after);
break;
case T_ExplainStmt:
@@ -443,6 +402,57 @@ transformStmt(ParseState *pstate, Node *parseTree,
return result;
}
+static Query *
+transformViewStmt(ParseState *pstate, ViewStmt *stmt,
+ List **extras_before, List **extras_after)
+{
+ Query *result = makeNode(Query);
+
+ result->commandType = CMD_UTILITY;
+ result->utilityStmt = (Node *) stmt;
+
+ stmt->query = transformStmt(pstate, (Node *) stmt->query,
+ extras_before, extras_after);
+
+ /*
+ * If a list of column names was given, run through and insert
+ * these into the actual query tree. - thomas 2000-03-08
+ *
+ * Outer loop is over targetlist to make it easier to skip junk
+ * targetlist entries.
+ */
+ if (stmt->aliases != NIL)
+ {
+ List *aliaslist = stmt->aliases;
+ List *targetList;
+
+ foreach(targetList, stmt->query->targetList)
+ {
+ TargetEntry *te = (TargetEntry *) lfirst(targetList);
+ Resdom *rd;
+
+ Assert(IsA(te, TargetEntry));
+ rd = te->resdom;
+ Assert(IsA(rd, Resdom));
+ /* junk columns don't get aliases */
+ if (rd->resjunk)
+ continue;
+ rd->resname = pstrdup(strVal(lfirst(aliaslist)));
+ aliaslist = lnext(aliaslist);
+ if (aliaslist == NIL)
+ break; /* done assigning aliases */
+ }
+
+ if (aliaslist != NIL)
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("CREATE VIEW specifies more column "
+ "names than columns")));
+ }
+
+ return result;
+}
+
/*
* transformDeleteStmt -
* transforms a Delete Statement