summaryrefslogtreecommitdiff
path: root/src/backend/parser/analyze.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/parser/analyze.c')
-rw-r--r--src/backend/parser/analyze.c88
1 files changed, 45 insertions, 43 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 397e951c71..97c560b309 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -17,7 +17,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.388 2009/01/22 20:16:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.389 2009/06/11 14:48:59 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -50,7 +50,7 @@ static Query *transformSelectStmt(ParseState *pstate, SelectStmt *stmt);
static Query *transformValuesClause(ParseState *pstate, SelectStmt *stmt);
static Query *transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt);
static Node *transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
- List **colInfo);
+ List **colInfo);
static void applyColumnNames(List *dst, List *src);
static Query *transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt);
static List *transformReturningList(ParseState *pstate, List *returningList);
@@ -59,7 +59,7 @@ static Query *transformDeclareCursorStmt(ParseState *pstate,
static Query *transformExplainStmt(ParseState *pstate,
ExplainStmt *stmt);
static void transformLockingClause(ParseState *pstate,
- Query *qry, LockingClause *lc);
+ Query *qry, LockingClause *lc);
static bool check_parameter_resolution_walker(Node *node, ParseState *pstate);
@@ -81,7 +81,7 @@ parse_analyze(Node *parseTree, const char *sourceText,
ParseState *pstate = make_parsestate(NULL);
Query *query;
- Assert(sourceText != NULL); /* required as of 8.4 */
+ Assert(sourceText != NULL); /* required as of 8.4 */
pstate->p_sourcetext = sourceText;
pstate->p_paramtypes = paramTypes;
@@ -109,7 +109,7 @@ parse_analyze_varparams(Node *parseTree, const char *sourceText,
ParseState *pstate = make_parsestate(NULL);
Query *query;
- Assert(sourceText != NULL); /* required as of 8.4 */
+ Assert(sourceText != NULL); /* required as of 8.4 */
pstate->p_sourcetext = sourceText;
pstate->p_paramtypes = *paramTypes;
@@ -255,6 +255,7 @@ analyze_requires_snapshot(Node *parseTree)
break;
case T_ExplainStmt:
+
/*
* We only need a snapshot in varparams case, but it doesn't seem
* worth complicating this function's API to distinguish that.
@@ -423,7 +424,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
* bugs of just that nature...)
*/
sub_pstate->p_rtable = sub_rtable;
- sub_pstate->p_joinexprs = NIL; /* sub_rtable has no joins */
+ sub_pstate->p_joinexprs = NIL; /* sub_rtable has no joins */
sub_pstate->p_relnamespace = sub_relnamespace;
sub_pstate->p_varnamespace = sub_varnamespace;
@@ -441,7 +442,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("INSERT ... SELECT cannot specify INTO"),
parser_errposition(pstate,
- exprLocation((Node *) selectQuery->intoClause))));
+ exprLocation((Node *) selectQuery->intoClause))));
/*
* Make the source be a subquery in the INSERT's rangetable, and add
@@ -485,11 +486,12 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
expr = tle->expr;
else
{
- Var *var = makeVar(rtr->rtindex,
- tle->resno,
- exprType((Node *) tle->expr),
- exprTypmod((Node *) tle->expr),
- 0);
+ Var *var = makeVar(rtr->rtindex,
+ tle->resno,
+ exprType((Node *) tle->expr),
+ exprTypmod((Node *) tle->expr),
+ 0);
+
var->location = exprLocation((Node *) tle->expr);
expr = (Expr *) var;
}
@@ -563,7 +565,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("VALUES must not contain table references"),
parser_errposition(pstate,
- locate_var_of_level((Node *) exprsLists, 0))));
+ locate_var_of_level((Node *) exprsLists, 0))));
/*
* Another thing we can't currently support is NEW/OLD references in
@@ -578,7 +580,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
errmsg("VALUES must not contain OLD or NEW references"),
errhint("Use SELECT ... UNION ALL ... instead."),
parser_errposition(pstate,
- locate_var_of_level((Node *) exprsLists, 0))));
+ locate_var_of_level((Node *) exprsLists, 0))));
/*
* Generate the VALUES RTE
@@ -655,7 +657,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
qry->targetList = lappend(qry->targetList, tle);
rte->modifiedCols = bms_add_member(rte->modifiedCols,
- attr_num - FirstLowInvalidHeapAttributeNumber);
+ attr_num - FirstLowInvalidHeapAttributeNumber);
icols = lnext(icols);
attnos = lnext(attnos);
@@ -727,7 +729,7 @@ transformInsertRow(ParseState *pstate, List *exprlist,
errmsg("INSERT has more expressions than target columns"),
parser_errposition(pstate,
exprLocation(list_nth(exprlist,
- list_length(icolumns))))));
+ list_length(icolumns))))));
if (stmtcols != NIL &&
list_length(exprlist) < list_length(icolumns))
ereport(ERROR,
@@ -735,7 +737,7 @@ transformInsertRow(ParseState *pstate, List *exprlist,
errmsg("INSERT has more target columns than expressions"),
parser_errposition(pstate,
exprLocation(list_nth(icolumns,
- list_length(exprlist))))));
+ list_length(exprlist))))));
/*
* Prepare columns for assignment to target table.
@@ -816,9 +818,9 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
/*
* Transform sorting/grouping stuff. Do ORDER BY first because both
- * transformGroupClause and transformDistinctClause need the results.
- * Note that these functions can also change the targetList, so it's
- * passed to them by reference.
+ * transformGroupClause and transformDistinctClause need the results. Note
+ * that these functions can also change the targetList, so it's passed to
+ * them by reference.
*/
qry->sortClause = transformSortClause(pstate,
stmt->sortClause,
@@ -1068,7 +1070,7 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("VALUES must not contain table references"),
parser_errposition(pstate,
- locate_var_of_level((Node *) newExprsLists, 0))));
+ locate_var_of_level((Node *) newExprsLists, 0))));
/*
* Another thing we can't currently support is NEW/OLD references in rules
@@ -1083,7 +1085,7 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
errmsg("VALUES must not contain OLD or NEW references"),
errhint("Use SELECT ... UNION ALL ... instead."),
parser_errposition(pstate,
- locate_var_of_level((Node *) newExprsLists, 0))));
+ locate_var_of_level((Node *) newExprsLists, 0))));
qry->rtable = pstate->p_rtable;
qry->jointree = makeFromExpr(pstate->p_joinlist, NULL);
@@ -1095,13 +1097,13 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
(errcode(ERRCODE_GROUPING_ERROR),
errmsg("cannot use aggregate function in VALUES"),
parser_errposition(pstate,
- locate_agg_of_level((Node *) newExprsLists, 0))));
+ locate_agg_of_level((Node *) newExprsLists, 0))));
if (pstate->p_hasWindowFuncs)
ereport(ERROR,
(errcode(ERRCODE_WINDOWING_ERROR),
errmsg("cannot use window function in VALUES"),
parser_errposition(pstate,
- locate_windowfunc((Node *) newExprsLists))));
+ locate_windowfunc((Node *) newExprsLists))));
return qry;
}
@@ -1302,7 +1304,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
errdetail("Only result column names can be used, not expressions or functions."),
errhint("Add the expression/function to every SELECT, or move the UNION into a FROM clause."),
parser_errposition(pstate,
- exprLocation(list_nth(qry->targetList, tllen)))));
+ exprLocation(list_nth(qry->targetList, tllen)))));
qry->limitOffset = transformLimitClause(pstate, limitOffset,
"OFFSET");
@@ -1368,7 +1370,7 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("INTO is only allowed on first SELECT of UNION/INTERSECT/EXCEPT"),
parser_errposition(pstate,
- exprLocation((Node *) stmt->intoClause))));
+ exprLocation((Node *) stmt->intoClause))));
/* We don't support FOR UPDATE/SHARE with set ops at the moment. */
if (stmt->lockingClause)
@@ -1428,7 +1430,7 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("UNION/INTERSECT/EXCEPT member statement cannot refer to other relations of same query level"),
parser_errposition(pstate,
- locate_var_of_level((Node *) selectQuery, 1))));
+ locate_var_of_level((Node *) selectQuery, 1))));
}
/*
@@ -1790,8 +1792,8 @@ transformReturningList(ParseState *pstate, List *returningList)
/* no new relation references please */
if (list_length(pstate->p_rtable) != length_rtable)
{
- int vlocation = -1;
- int relid;
+ int vlocation = -1;
+ int relid;
/* try to locate such a reference to point to */
for (relid = length_rtable + 1; relid <= list_length(pstate->p_rtable); relid++)
@@ -1802,7 +1804,7 @@ transformReturningList(ParseState *pstate, List *returningList)
}
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("RETURNING cannot contain references to other relations"),
+ errmsg("RETURNING cannot contain references to other relations"),
parser_errposition(pstate, vlocation)));
}
@@ -1857,7 +1859,7 @@ transformDeclareCursorStmt(ParseState *pstate, DeclareCursorStmt *stmt)
(errcode(ERRCODE_INVALID_CURSOR_DEFINITION),
errmsg("DECLARE CURSOR cannot specify INTO"),
parser_errposition(pstate,
- exprLocation((Node *) result->intoClause))));
+ exprLocation((Node *) result->intoClause))));
/* FOR UPDATE and WITH HOLD are not compatible */
if (result->rowMarks != NIL && (stmt->options & CURSOR_OPT_HOLD))
@@ -2006,10 +2008,10 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc)
{
/*
* We allow FOR UPDATE/SHARE of a WITH query to be
- * propagated into the WITH, but it doesn't seem
- * very sane to allow this for a reference to an
- * outer-level WITH. And it definitely wouldn't
- * work for a self-reference, since we're not done
+ * propagated into the WITH, but it doesn't seem very
+ * sane to allow this for a reference to an
+ * outer-level WITH. And it definitely wouldn't work
+ * for a self-reference, since we're not done
* analyzing the CTE anyway.
*/
CommonTableExpr *cte;
@@ -2073,25 +2075,25 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("SELECT FOR UPDATE/SHARE cannot be applied to a join"),
- parser_errposition(pstate, thisrel->location)));
+ parser_errposition(pstate, thisrel->location)));
break;
case RTE_SPECIAL:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("SELECT FOR UPDATE/SHARE cannot be applied to NEW or OLD"),
- parser_errposition(pstate, thisrel->location)));
+ parser_errposition(pstate, thisrel->location)));
break;
case RTE_FUNCTION:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("SELECT FOR UPDATE/SHARE cannot be applied to a function"),
- parser_errposition(pstate, thisrel->location)));
+ parser_errposition(pstate, thisrel->location)));
break;
case RTE_VALUES:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("SELECT FOR UPDATE/SHARE cannot be applied to VALUES"),
- parser_errposition(pstate, thisrel->location)));
+ parser_errposition(pstate, thisrel->location)));
break;
case RTE_CTE:
{
@@ -2108,14 +2110,14 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc)
if (rte->ctelevelsup > 0 || rte->self_reference)
ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("SELECT FOR UPDATE/SHARE cannot be applied to an outer-level WITH query"),
- parser_errposition(pstate, thisrel->location)));
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("SELECT FOR UPDATE/SHARE cannot be applied to an outer-level WITH query"),
+ parser_errposition(pstate, thisrel->location)));
cte = GetCTEForRTE(pstate, rte, -1);
/* should be analyzed by now */
Assert(IsA(cte->ctequery, Query));
transformLockingClause(pstate,
- (Query *) cte->ctequery,
+ (Query *) cte->ctequery,
allrels);
}
break;