mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Pgindent run for 8.0.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.310 2004/08/29 04:12:35 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.311 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -100,7 +100,7 @@ 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);
|
||||
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);
|
||||
@@ -403,7 +403,7 @@ static Query *
|
||||
transformViewStmt(ParseState *pstate, ViewStmt *stmt,
|
||||
List **extras_before, List **extras_after)
|
||||
{
|
||||
Query *result = makeNode(Query);
|
||||
Query *result = makeNode(Query);
|
||||
|
||||
result->commandType = CMD_UTILITY;
|
||||
result->utilityStmt = (Node *) stmt;
|
||||
@@ -412,16 +412,16 @@ transformViewStmt(ParseState *pstate, ViewStmt *stmt,
|
||||
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
|
||||
* 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)
|
||||
{
|
||||
ListCell *alist_item = list_head(stmt->aliases);
|
||||
ListCell *targetList;
|
||||
ListCell *alist_item = list_head(stmt->aliases);
|
||||
ListCell *targetList;
|
||||
|
||||
foreach(targetList, stmt->query->targetList)
|
||||
{
|
||||
@@ -437,7 +437,7 @@ transformViewStmt(ParseState *pstate, ViewStmt *stmt,
|
||||
rd->resname = pstrdup(strVal(lfirst(alist_item)));
|
||||
alist_item = lnext(alist_item);
|
||||
if (alist_item == NULL)
|
||||
break; /* done assigning aliases */
|
||||
break; /* done assigning aliases */
|
||||
}
|
||||
|
||||
if (alist_item != NULL)
|
||||
@@ -846,13 +846,13 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
|
||||
/*
|
||||
* Determine namespace and name to use for the sequence.
|
||||
*
|
||||
* Although we use ChooseRelationName, it's not guaranteed that
|
||||
* the selected sequence name won't conflict; given sufficiently
|
||||
* long field names, two different serial columns in the same table
|
||||
* Although we use ChooseRelationName, it's not guaranteed that the
|
||||
* selected sequence name won't conflict; given sufficiently long
|
||||
* field names, two different serial columns in the same table
|
||||
* could be assigned the same sequence name, and we'd not notice
|
||||
* since we aren't creating the sequence quite yet. In practice
|
||||
* this seems quite unlikely to be a problem, especially since
|
||||
* few people would need two serial columns in one table.
|
||||
* this seems quite unlikely to be a problem, especially since few
|
||||
* people would need two serial columns in one table.
|
||||
*/
|
||||
snamespaceid = RangeVarGetCreationNamespace(cxt->relation);
|
||||
snamespace = get_namespace_name(snamespaceid);
|
||||
@@ -946,7 +946,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
|
||||
column->colname, cxt->relation->relname)));
|
||||
column->colname, cxt->relation->relname)));
|
||||
column->is_not_null = FALSE;
|
||||
saw_nullable = true;
|
||||
break;
|
||||
@@ -956,7 +956,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
|
||||
column->colname, cxt->relation->relname)));
|
||||
column->colname, cxt->relation->relname)));
|
||||
column->is_not_null = TRUE;
|
||||
saw_nullable = true;
|
||||
break;
|
||||
@@ -966,7 +966,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multiple default values specified for column \"%s\" of table \"%s\"",
|
||||
column->colname, cxt->relation->relname)));
|
||||
column->colname, cxt->relation->relname)));
|
||||
column->raw_default = constraint->raw_expr;
|
||||
Assert(constraint->cooked_expr == NULL);
|
||||
break;
|
||||
@@ -1185,6 +1185,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
|
||||
errmsg("multiple primary keys for table \"%s\" are not allowed",
|
||||
cxt->relation->relname)));
|
||||
cxt->pkey = index;
|
||||
|
||||
/*
|
||||
* In ALTER TABLE case, a primary index might already exist,
|
||||
* but DefineIndex will check for it.
|
||||
@@ -1363,11 +1364,10 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
|
||||
if (equal(index->indexParams, priorindex->indexParams))
|
||||
{
|
||||
/*
|
||||
* If the prior index is as yet unnamed, and this one
|
||||
* is named, then transfer the name to the prior
|
||||
* index. This ensures that if we have named and
|
||||
* unnamed constraints, we'll use (at least one of)
|
||||
* the names for the index.
|
||||
* If the prior index is as yet unnamed, and this one is
|
||||
* named, then transfer the name to the prior index. This
|
||||
* ensures that if we have named and unnamed constraints,
|
||||
* we'll use (at least one of) the names for the index.
|
||||
*/
|
||||
if (priorindex->idxname == NULL)
|
||||
priorindex->idxname = index->idxname;
|
||||
@@ -1406,9 +1406,9 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt,
|
||||
|
||||
/*
|
||||
* For CREATE TABLE or ALTER TABLE ADD COLUMN, gin up an ALTER TABLE
|
||||
* ADD CONSTRAINT command to execute after the basic command is complete.
|
||||
* (If called from ADD CONSTRAINT, that routine will add the FK constraints
|
||||
* to its own subcommand list.)
|
||||
* ADD CONSTRAINT command to execute after the basic command is
|
||||
* complete. (If called from ADD CONSTRAINT, that routine will add the
|
||||
* FK constraints to its own subcommand list.)
|
||||
*
|
||||
* Note: the ADD CONSTRAINT command must also execute after any index
|
||||
* creation commands. Thus, this should run after
|
||||
@@ -1426,7 +1426,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt,
|
||||
foreach(fkclist, cxt->fkconstraints)
|
||||
{
|
||||
FkConstraint *fkconstraint = (FkConstraint *) lfirst(fkclist);
|
||||
AlterTableCmd *altercmd = makeNode(AlterTableCmd);
|
||||
AlterTableCmd *altercmd = makeNode(AlterTableCmd);
|
||||
|
||||
altercmd->subtype = AT_ProcessedConstraint;
|
||||
altercmd->name = NULL;
|
||||
@@ -1585,7 +1585,7 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
|
||||
stmt->whereClause = transformWhereClause(pstate, stmt->whereClause,
|
||||
"WHERE");
|
||||
|
||||
if (list_length(pstate->p_rtable) != 2) /* naughty, naughty... */
|
||||
if (list_length(pstate->p_rtable) != 2) /* naughty, naughty... */
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("rule WHERE condition may not contain references to other relations")));
|
||||
@@ -2273,8 +2273,8 @@ getSetColTypes(ParseState *pstate, Node *node)
|
||||
static void
|
||||
applyColumnNames(List *dst, List *src)
|
||||
{
|
||||
ListCell *dst_item = list_head(dst);
|
||||
ListCell *src_item = list_head(src);
|
||||
ListCell *dst_item = list_head(dst);
|
||||
ListCell *src_item = list_head(src);
|
||||
|
||||
if (list_length(src) > list_length(dst))
|
||||
ereport(ERROR,
|
||||
@@ -2356,9 +2356,9 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
|
||||
{
|
||||
/*
|
||||
* Resjunk nodes need no additional processing, but be sure
|
||||
* they have resnos that do not match any target columns;
|
||||
* else rewriter or planner might get confused. They don't
|
||||
* need a resname either.
|
||||
* they have resnos that do not match any target columns; else
|
||||
* rewriter or planner might get confused. They don't need a
|
||||
* resname either.
|
||||
*/
|
||||
resnode->resno = (AttrNumber) pstate->p_next_resno++;
|
||||
resnode->resname = NULL;
|
||||
@@ -2396,7 +2396,7 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
|
||||
*l;
|
||||
List *newcmds = NIL;
|
||||
bool skipValidation = true;
|
||||
AlterTableCmd *newcmd;
|
||||
AlterTableCmd *newcmd;
|
||||
|
||||
cxt.stmtType = "ALTER TABLE";
|
||||
cxt.relation = stmt->relation;
|
||||
@@ -2413,58 +2413,62 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
|
||||
|
||||
/*
|
||||
* The only subtypes that currently require parse transformation
|
||||
* handling are ADD COLUMN and ADD CONSTRAINT. These largely
|
||||
* re-use code from CREATE TABLE.
|
||||
* handling are ADD COLUMN and ADD CONSTRAINT. These largely re-use
|
||||
* code from CREATE TABLE.
|
||||
*/
|
||||
foreach(lcmd, stmt->cmds)
|
||||
{
|
||||
AlterTableCmd *cmd = (AlterTableCmd *) lfirst(lcmd);
|
||||
AlterTableCmd *cmd = (AlterTableCmd *) lfirst(lcmd);
|
||||
|
||||
switch (cmd->subtype)
|
||||
{
|
||||
case AT_AddColumn:
|
||||
{
|
||||
ColumnDef *def = (ColumnDef *) cmd->def;
|
||||
|
||||
Assert(IsA(cmd->def, ColumnDef));
|
||||
transformColumnDefinition(pstate, &cxt,
|
||||
(ColumnDef *) cmd->def);
|
||||
|
||||
/*
|
||||
* If the column has a non-null default, we can't skip
|
||||
* validation of foreign keys.
|
||||
*/
|
||||
if (((ColumnDef *) cmd->def)->raw_default != NULL)
|
||||
skipValidation = false;
|
||||
|
||||
newcmds = lappend(newcmds, cmd);
|
||||
|
||||
/*
|
||||
* Convert an ADD COLUMN ... NOT NULL constraint to a separate
|
||||
* command
|
||||
*/
|
||||
if (def->is_not_null)
|
||||
{
|
||||
/* Remove NOT NULL from AddColumn */
|
||||
def->is_not_null = false;
|
||||
ColumnDef *def = (ColumnDef *) cmd->def;
|
||||
|
||||
/* Add as a separate AlterTableCmd */
|
||||
newcmd = makeNode(AlterTableCmd);
|
||||
newcmd->subtype = AT_SetNotNull;
|
||||
newcmd->name = pstrdup(def->colname);
|
||||
newcmds = lappend(newcmds, newcmd);
|
||||
Assert(IsA(cmd->def, ColumnDef));
|
||||
transformColumnDefinition(pstate, &cxt,
|
||||
(ColumnDef *) cmd->def);
|
||||
|
||||
/*
|
||||
* If the column has a non-null default, we can't skip
|
||||
* validation of foreign keys.
|
||||
*/
|
||||
if (((ColumnDef *) cmd->def)->raw_default != NULL)
|
||||
skipValidation = false;
|
||||
|
||||
newcmds = lappend(newcmds, cmd);
|
||||
|
||||
/*
|
||||
* Convert an ADD COLUMN ... NOT NULL constraint to a
|
||||
* separate command
|
||||
*/
|
||||
if (def->is_not_null)
|
||||
{
|
||||
/* Remove NOT NULL from AddColumn */
|
||||
def->is_not_null = false;
|
||||
|
||||
/* Add as a separate AlterTableCmd */
|
||||
newcmd = makeNode(AlterTableCmd);
|
||||
newcmd->subtype = AT_SetNotNull;
|
||||
newcmd->name = pstrdup(def->colname);
|
||||
newcmds = lappend(newcmds, newcmd);
|
||||
}
|
||||
|
||||
/*
|
||||
* All constraints are processed in other ways. Remove
|
||||
* the original list
|
||||
*/
|
||||
def->constraints = NIL;
|
||||
|
||||
break;
|
||||
}
|
||||
case AT_AddConstraint:
|
||||
|
||||
/*
|
||||
* All constraints are processed in other ways.
|
||||
* Remove the original list
|
||||
* The original AddConstraint cmd node doesn't go to
|
||||
* newcmds
|
||||
*/
|
||||
def->constraints = NIL;
|
||||
|
||||
break;
|
||||
}
|
||||
case AT_AddConstraint:
|
||||
/* The original AddConstraint cmd node doesn't go to newcmds */
|
||||
|
||||
if (IsA(cmd->def, Constraint))
|
||||
transformTableConstraint(pstate, &cxt,
|
||||
@@ -2482,8 +2486,8 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
|
||||
case AT_ProcessedConstraint:
|
||||
|
||||
/*
|
||||
* Already-transformed ADD CONSTRAINT, so just make it look
|
||||
* like the standard case.
|
||||
* Already-transformed ADD CONSTRAINT, so just make it
|
||||
* look like the standard case.
|
||||
*/
|
||||
cmd->subtype = AT_AddConstraint;
|
||||
newcmds = lappend(newcmds, cmd);
|
||||
@@ -2501,12 +2505,12 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
|
||||
transformFKConstraints(pstate, &cxt, skipValidation, true);
|
||||
|
||||
/*
|
||||
* Push any index-creation commands into the ALTER, so that
|
||||
* they can be scheduled nicely by tablecmds.c.
|
||||
* Push any index-creation commands into the ALTER, so that they can
|
||||
* be scheduled nicely by tablecmds.c.
|
||||
*/
|
||||
foreach(l, cxt.alist)
|
||||
{
|
||||
Node *idxstmt = (Node *) lfirst(l);
|
||||
Node *idxstmt = (Node *) lfirst(l);
|
||||
|
||||
Assert(IsA(idxstmt, IndexStmt));
|
||||
newcmd = makeNode(AlterTableCmd);
|
||||
@@ -2642,7 +2646,8 @@ transformExecuteStmt(ParseState *pstate, ExecuteStmt *stmt)
|
||||
{
|
||||
int nparams = list_length(stmt->params);
|
||||
int nexpected = list_length(paramtypes);
|
||||
ListCell *l, *l2;
|
||||
ListCell *l,
|
||||
*l2;
|
||||
int i = 1;
|
||||
|
||||
if (nparams != nexpected)
|
||||
@@ -2665,11 +2670,11 @@ transformExecuteStmt(ParseState *pstate, ExecuteStmt *stmt)
|
||||
if (pstate->p_hasSubLinks)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot use subquery in EXECUTE parameter")));
|
||||
errmsg("cannot use subquery in EXECUTE parameter")));
|
||||
if (pstate->p_hasAggs)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("cannot use aggregate function in EXECUTE parameter")));
|
||||
errmsg("cannot use aggregate function in EXECUTE parameter")));
|
||||
|
||||
given_type_id = exprType(expr);
|
||||
|
||||
@@ -2714,7 +2719,7 @@ CheckSelectForUpdate(Query *qry)
|
||||
if (qry->hasAggs)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE is not allowed with aggregate functions")));
|
||||
errmsg("SELECT FOR UPDATE is not allowed with aggregate functions")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2750,6 +2755,7 @@ transformForUpdate(Query *qry, List *forUpdate)
|
||||
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
|
||||
break;
|
||||
case RTE_SUBQUERY:
|
||||
|
||||
/*
|
||||
* FOR UPDATE of subquery is propagated to subquery's
|
||||
* rels
|
||||
@@ -2780,11 +2786,12 @@ transformForUpdate(Query *qry, List *forUpdate)
|
||||
switch (rte->rtekind)
|
||||
{
|
||||
case RTE_RELATION:
|
||||
if (!list_member_int(rowMarks, i)) /* avoid duplicates */
|
||||
if (!list_member_int(rowMarks, i)) /* avoid duplicates */
|
||||
rowMarks = lappend_int(rowMarks, i);
|
||||
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
|
||||
break;
|
||||
case RTE_SUBQUERY:
|
||||
|
||||
/*
|
||||
* FOR UPDATE of subquery is propagated to
|
||||
* subquery's rels
|
||||
@@ -2793,18 +2800,18 @@ transformForUpdate(Query *qry, List *forUpdate)
|
||||
break;
|
||||
case RTE_JOIN:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE cannot be applied to a join")));
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE cannot be applied to a join")));
|
||||
break;
|
||||
case RTE_SPECIAL:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE cannot be applied to NEW or OLD")));
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE cannot be applied to NEW or OLD")));
|
||||
break;
|
||||
case RTE_FUNCTION:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE cannot be applied to a function")));
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE cannot be applied to a function")));
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "unrecognized RTE type: %d",
|
||||
@@ -3065,7 +3072,7 @@ analyzeCreateSchemaStmt(CreateSchemaStmt *stmt)
|
||||
|
||||
case T_IndexStmt:
|
||||
{
|
||||
IndexStmt *elp = (IndexStmt *) element;
|
||||
IndexStmt *elp = (IndexStmt *) element;
|
||||
|
||||
setSchemaName(cxt.schemaname, &elp->relation->schemaname);
|
||||
cxt.indexes = lappend(cxt.indexes, element);
|
||||
@@ -3131,8 +3138,8 @@ check_parameter_resolution_walker(Node *node,
|
||||
if (param->paramtype != context->paramTypes[paramno - 1])
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_PARAMETER),
|
||||
errmsg("could not determine data type of parameter $%d",
|
||||
paramno)));
|
||||
errmsg("could not determine data type of parameter $%d",
|
||||
paramno)));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_agg.c,v 1.64 2004/08/29 04:12:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_agg.c,v 1.65 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -307,7 +307,7 @@ check_ungrouped_columns_walker(Node *node,
|
||||
|
||||
/* Found an ungrouped local variable; generate error message */
|
||||
Assert(var->varno > 0 &&
|
||||
(int) var->varno <= list_length(context->pstate->p_rtable));
|
||||
(int) var->varno <= list_length(context->pstate->p_rtable));
|
||||
rte = rt_fetch(var->varno, context->pstate->p_rtable);
|
||||
attname = get_rte_attribute_name(rte, var->varattno);
|
||||
if (context->sublevels_up == 0)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.135 2004/08/29 04:12:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.136 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -158,7 +158,8 @@ setTargetTable(ParseState *pstate, RangeVar *relation,
|
||||
*
|
||||
* If we find an explicit reference to the rel later during parse
|
||||
* analysis, scanRTEForColumn will add the ACL_SELECT bit back again.
|
||||
* That can't happen for INSERT but it is possible for UPDATE and DELETE.
|
||||
* That can't happen for INSERT but it is possible for UPDATE and
|
||||
* DELETE.
|
||||
*/
|
||||
rte->requiredPerms = requiredPerms;
|
||||
|
||||
@@ -231,7 +232,8 @@ extractRemainingColumns(List *common_colnames,
|
||||
{
|
||||
List *new_colnames = NIL;
|
||||
List *new_colvars = NIL;
|
||||
ListCell *lnames, *lvars;
|
||||
ListCell *lnames,
|
||||
*lvars;
|
||||
|
||||
Assert(list_length(src_colnames) == list_length(src_colvars));
|
||||
|
||||
@@ -272,7 +274,8 @@ static Node *
|
||||
transformJoinUsingClause(ParseState *pstate, List *leftVars, List *rightVars)
|
||||
{
|
||||
Node *result = NULL;
|
||||
ListCell *lvars, *rvars;
|
||||
ListCell *lvars,
|
||||
*rvars;
|
||||
|
||||
/*
|
||||
* We cheat a little bit here by building an untransformed operator
|
||||
@@ -1139,11 +1142,11 @@ findTargetlistEntry(ParseState *pstate, Node *node, List **tlist, int clause)
|
||||
*
|
||||
* Small tweak for 7.4.3: ignore matches in upper query levels.
|
||||
* This effectively changes the search order for bare names to
|
||||
* (1) local FROM variables, (2) local targetlist aliases,
|
||||
* (3) outer FROM variables, whereas before it was (1) (3) (2).
|
||||
* SQL92 and SQL99 do not allow GROUPing BY an outer reference,
|
||||
* so this breaks no cases that are legal per spec, and it
|
||||
* seems a more self-consistent behavior.
|
||||
* (1) local FROM variables, (2) local targetlist aliases, (3)
|
||||
* outer FROM variables, whereas before it was (1) (3) (2).
|
||||
* SQL92 and SQL99 do not allow GROUPing BY an outer
|
||||
* reference, so this breaks no cases that are legal per spec,
|
||||
* and it seems a more self-consistent behavior.
|
||||
*/
|
||||
if (colNameToVar(pstate, name, true) != NULL)
|
||||
name = NULL;
|
||||
@@ -1164,7 +1167,11 @@ findTargetlistEntry(ParseState *pstate, Node *node, List **tlist, int clause)
|
||||
if (!equal(target_result->expr, tle->expr))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_COLUMN),
|
||||
/* translator: first %s is name of a SQL construct, eg ORDER BY */
|
||||
|
||||
/*
|
||||
* translator: first %s is name of a SQL
|
||||
* construct, eg ORDER BY
|
||||
*/
|
||||
errmsg("%s \"%s\" is ambiguous",
|
||||
clauseText[clause], name)));
|
||||
}
|
||||
@@ -1444,7 +1451,7 @@ transformDistinctClause(ParseState *pstate, List *distinctlist,
|
||||
else
|
||||
{
|
||||
*sortClause = addTargetToSortList(pstate, tle,
|
||||
*sortClause, *targetlist,
|
||||
*sortClause, *targetlist,
|
||||
SORTBY_ASC, NIL, true);
|
||||
|
||||
/*
|
||||
@@ -1484,7 +1491,7 @@ List *
|
||||
addAllTargetsToSortList(ParseState *pstate, List *sortlist,
|
||||
List *targetlist, bool resolveUnknown)
|
||||
{
|
||||
ListCell *l;
|
||||
ListCell *l;
|
||||
|
||||
foreach(l, targetlist)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.122 2004/08/29 04:12:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.123 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -33,17 +33,17 @@
|
||||
|
||||
|
||||
static Node *coerce_type_typmod(Node *node,
|
||||
Oid targetTypeId, int32 targetTypMod,
|
||||
CoercionForm cformat, bool isExplicit,
|
||||
bool hideInputCoercion);
|
||||
Oid targetTypeId, int32 targetTypMod,
|
||||
CoercionForm cformat, bool isExplicit,
|
||||
bool hideInputCoercion);
|
||||
static void hide_coercion_node(Node *node);
|
||||
static Node *build_coercion_expression(Node *node, Oid funcId,
|
||||
Oid targetTypeId, int32 targetTypMod,
|
||||
CoercionForm cformat, bool isExplicit);
|
||||
Oid targetTypeId, int32 targetTypMod,
|
||||
CoercionForm cformat, bool isExplicit);
|
||||
static Node *coerce_record_to_complex(ParseState *pstate, Node *node,
|
||||
Oid targetTypeId,
|
||||
CoercionContext ccontext,
|
||||
CoercionForm cformat);
|
||||
Oid targetTypeId,
|
||||
CoercionContext ccontext,
|
||||
CoercionForm cformat);
|
||||
|
||||
|
||||
/*
|
||||
@@ -72,7 +72,7 @@ coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype,
|
||||
CoercionContext ccontext,
|
||||
CoercionForm cformat)
|
||||
{
|
||||
Node *result;
|
||||
Node *result;
|
||||
|
||||
if (!can_coerce_type(1, &exprtype, &targettype, ccontext))
|
||||
return NULL;
|
||||
@@ -83,7 +83,7 @@ coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype,
|
||||
|
||||
/*
|
||||
* If the target is a fixed-length type, it may need a length coercion
|
||||
* as well as a type coercion. If we find ourselves adding both,
|
||||
* as well as a type coercion. If we find ourselves adding both,
|
||||
* force the inner coercion node to implicit display form.
|
||||
*/
|
||||
result = coerce_type_typmod(result,
|
||||
@@ -253,14 +253,15 @@ coerce_type(ParseState *pstate, Node *node,
|
||||
* Generate an expression tree representing run-time
|
||||
* application of the conversion function. If we are dealing
|
||||
* with a domain target type, the conversion function will
|
||||
* yield the base type (and we assume targetTypeMod must be -1).
|
||||
* yield the base type (and we assume targetTypeMod must be
|
||||
* -1).
|
||||
*/
|
||||
Oid baseTypeId = getBaseType(targetTypeId);
|
||||
|
||||
result = build_coercion_expression(node, funcId,
|
||||
baseTypeId, targetTypeMod,
|
||||
cformat,
|
||||
(cformat != COERCE_IMPLICIT_CAST));
|
||||
(cformat != COERCE_IMPLICIT_CAST));
|
||||
|
||||
/*
|
||||
* If domain, coerce to the domain type and relabel with
|
||||
@@ -384,8 +385,8 @@ can_coerce_type(int nargs, Oid *input_typeids, Oid *target_typeids,
|
||||
continue;
|
||||
|
||||
/*
|
||||
* If input is RECORD and target is a composite type, assume
|
||||
* we can coerce (may need tighter checking here)
|
||||
* If input is RECORD and target is a composite type, assume we
|
||||
* can coerce (may need tighter checking here)
|
||||
*/
|
||||
if (inputTypeId == RECORDOID &&
|
||||
ISCOMPLEX(targetTypeId))
|
||||
@@ -538,7 +539,7 @@ coerce_type_typmod(Node *node, Oid targetTypeId, int32 targetTypMod,
|
||||
* Mark a coercion node as IMPLICIT so it will never be displayed by
|
||||
* ruleutils.c. We use this when we generate a nest of coercion nodes
|
||||
* to implement what is logically one conversion; the inner nodes are
|
||||
* forced to IMPLICIT_CAST format. This does not change their semantics,
|
||||
* forced to IMPLICIT_CAST format. This does not change their semantics,
|
||||
* only display behavior.
|
||||
*
|
||||
* It is caller error to call this on something that doesn't have a
|
||||
@@ -585,9 +586,9 @@ build_coercion_expression(Node *node, Oid funcId,
|
||||
procstruct = (Form_pg_proc) GETSTRUCT(tp);
|
||||
|
||||
/*
|
||||
* Asserts essentially check that function is a legal coercion function.
|
||||
* We can't make the seemingly obvious tests on prorettype and
|
||||
* proargtypes[0], because of various binary-compatibility cases.
|
||||
* Asserts essentially check that function is a legal coercion
|
||||
* function. We can't make the seemingly obvious tests on prorettype
|
||||
* and proargtypes[0], because of various binary-compatibility cases.
|
||||
*/
|
||||
/* Assert(targetTypeId == procstruct->prorettype); */
|
||||
Assert(!procstruct->proretset);
|
||||
@@ -643,7 +644,7 @@ coerce_record_to_complex(ParseState *pstate, Node *node,
|
||||
CoercionContext ccontext,
|
||||
CoercionForm cformat)
|
||||
{
|
||||
RowExpr *rowexpr;
|
||||
RowExpr *rowexpr;
|
||||
TupleDesc tupdesc;
|
||||
List *args = NIL;
|
||||
List *newargs;
|
||||
@@ -662,9 +663,9 @@ coerce_record_to_complex(ParseState *pstate, Node *node,
|
||||
else if (node && IsA(node, Var) &&
|
||||
((Var *) node)->varattno == InvalidAttrNumber)
|
||||
{
|
||||
int rtindex = ((Var *) node)->varno;
|
||||
int sublevels_up = ((Var *) node)->varlevelsup;
|
||||
List *rtable;
|
||||
int rtindex = ((Var *) node)->varno;
|
||||
int sublevels_up = ((Var *) node)->varlevelsup;
|
||||
List *rtable;
|
||||
|
||||
rtable = GetLevelNRangeTable(pstate, sublevels_up);
|
||||
expandRTE(rtable, rtindex, sublevels_up, false, NULL, &args);
|
||||
@@ -682,15 +683,15 @@ coerce_record_to_complex(ParseState *pstate, Node *node,
|
||||
arg = list_head(args);
|
||||
for (i = 0; i < tupdesc->natts; i++)
|
||||
{
|
||||
Node *expr;
|
||||
Oid exprtype;
|
||||
Node *expr;
|
||||
Oid exprtype;
|
||||
|
||||
/* Fill in NULLs for dropped columns in rowtype */
|
||||
if (tupdesc->attrs[i]->attisdropped)
|
||||
{
|
||||
/*
|
||||
* can't use atttypid here, but it doesn't really matter
|
||||
* what type the Const claims to be.
|
||||
* can't use atttypid here, but it doesn't really matter what
|
||||
* type the Const claims to be.
|
||||
*/
|
||||
newargs = lappend(newargs, makeNullConst(INT4OID));
|
||||
continue;
|
||||
@@ -720,7 +721,7 @@ coerce_record_to_complex(ParseState *pstate, Node *node,
|
||||
format_type_be(targetTypeId)),
|
||||
errdetail("Cannot cast type %s to %s in column %d.",
|
||||
format_type_be(exprtype),
|
||||
format_type_be(tupdesc->attrs[i]->atttypid),
|
||||
format_type_be(tupdesc->attrs[i]->atttypid),
|
||||
ucolno)));
|
||||
newargs = lappend(newargs, expr);
|
||||
ucolno++;
|
||||
@@ -862,6 +863,7 @@ select_common_type(List *typeids, const char *context)
|
||||
*/
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
|
||||
/*
|
||||
* translator: first %s is name of a SQL construct, eg
|
||||
* CASE
|
||||
@@ -1104,7 +1106,7 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
|
||||
if (OidIsValid(elem_typeid) && actual_type != elem_typeid)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("arguments declared \"anyelement\" are not all alike"),
|
||||
errmsg("arguments declared \"anyelement\" are not all alike"),
|
||||
errdetail("%s versus %s",
|
||||
format_type_be(elem_typeid),
|
||||
format_type_be(actual_type))));
|
||||
@@ -1121,7 +1123,7 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
|
||||
if (OidIsValid(array_typeid) && actual_type != array_typeid)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("arguments declared \"anyarray\" are not all alike"),
|
||||
errmsg("arguments declared \"anyarray\" are not all alike"),
|
||||
errdetail("%s versus %s",
|
||||
format_type_be(array_typeid),
|
||||
format_type_be(actual_type))));
|
||||
@@ -1220,8 +1222,8 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
|
||||
if (!OidIsValid(array_typeid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("could not find array type for data type %s",
|
||||
format_type_be(elem_typeid))));
|
||||
errmsg("could not find array type for data type %s",
|
||||
format_type_be(elem_typeid))));
|
||||
}
|
||||
return array_typeid;
|
||||
}
|
||||
@@ -1274,8 +1276,8 @@ resolve_generic_type(Oid declared_type,
|
||||
if (!OidIsValid(array_typeid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("could not find array type for data type %s",
|
||||
format_type_be(context_actual_type))));
|
||||
errmsg("could not find array type for data type %s",
|
||||
format_type_be(context_actual_type))));
|
||||
return array_typeid;
|
||||
}
|
||||
}
|
||||
@@ -1647,8 +1649,9 @@ find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
|
||||
{
|
||||
/*
|
||||
* If there's no pg_cast entry, perhaps we are dealing with a pair
|
||||
* of array types. If so, and if the element types have a suitable
|
||||
* cast, use array_type_coerce() or array_type_length_coerce().
|
||||
* of array types. If so, and if the element types have a
|
||||
* suitable cast, use array_type_coerce() or
|
||||
* array_type_length_coerce().
|
||||
*/
|
||||
Oid targetElemType;
|
||||
Oid sourceElemType;
|
||||
@@ -1668,8 +1671,8 @@ find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
|
||||
else
|
||||
{
|
||||
/* does the function take a typmod arg? */
|
||||
Oid argtypes[FUNC_MAX_ARGS];
|
||||
int nargs;
|
||||
Oid argtypes[FUNC_MAX_ARGS];
|
||||
int nargs;
|
||||
|
||||
(void) get_func_signature(elemfuncid, argtypes, &nargs);
|
||||
if (nargs > 1)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.175 2004/08/29 04:12:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.176 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -39,17 +39,17 @@ bool Transform_null_equals = false;
|
||||
|
||||
static Node *transformColumnRef(ParseState *pstate, ColumnRef *cref);
|
||||
static Node *transformWholeRowRef(ParseState *pstate, char *schemaname,
|
||||
char *relname);
|
||||
char *relname);
|
||||
static Node *transformIndirection(ParseState *pstate, Node *basenode,
|
||||
List *indirection);
|
||||
static Node *typecast_expression(ParseState *pstate, Node *expr,
|
||||
TypeName *typename);
|
||||
static Node *make_row_op(ParseState *pstate, List *opname,
|
||||
Node *ltree, Node *rtree);
|
||||
Node *ltree, Node *rtree);
|
||||
static Node *make_row_distinct_op(ParseState *pstate, List *opname,
|
||||
Node *ltree, Node *rtree);
|
||||
Node *ltree, Node *rtree);
|
||||
static Expr *make_distinct_op(ParseState *pstate, List *opname,
|
||||
Node *ltree, Node *rtree);
|
||||
Node *ltree, Node *rtree);
|
||||
|
||||
|
||||
/*
|
||||
@@ -162,7 +162,7 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
}
|
||||
case T_A_Indirection:
|
||||
{
|
||||
A_Indirection *ind = (A_Indirection *) expr;
|
||||
A_Indirection *ind = (A_Indirection *) expr;
|
||||
|
||||
result = transformExpr(pstate, ind->arg);
|
||||
result = transformIndirection(pstate, result,
|
||||
@@ -196,7 +196,7 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
*/
|
||||
if (Transform_null_equals &&
|
||||
list_length(a->name) == 1 &&
|
||||
strcmp(strVal(linitial(a->name)), "=") == 0 &&
|
||||
strcmp(strVal(linitial(a->name)), "=") == 0 &&
|
||||
(exprIsNullConstant(lexpr) ||
|
||||
exprIsNullConstant(rexpr)))
|
||||
{
|
||||
@@ -218,12 +218,12 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
{
|
||||
/*
|
||||
* Convert "row op subselect" into a
|
||||
* MULTIEXPR sublink. Formerly the grammar
|
||||
* did this, but now that a row construct is
|
||||
* allowed anywhere in expressions, it's
|
||||
* easier to do it here.
|
||||
* MULTIEXPR sublink. Formerly the
|
||||
* grammar did this, but now that a row
|
||||
* construct is allowed anywhere in
|
||||
* expressions, it's easier to do it here.
|
||||
*/
|
||||
SubLink *s = (SubLink *) rexpr;
|
||||
SubLink *s = (SubLink *) rexpr;
|
||||
|
||||
s->subLinkType = MULTIEXPR_SUBLINK;
|
||||
s->lefthand = ((RowExpr *) lexpr)->args;
|
||||
@@ -261,8 +261,8 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
rexpr = coerce_to_boolean(pstate, rexpr, "AND");
|
||||
|
||||
result = (Node *) makeBoolExpr(AND_EXPR,
|
||||
list_make2(lexpr,
|
||||
rexpr));
|
||||
list_make2(lexpr,
|
||||
rexpr));
|
||||
}
|
||||
break;
|
||||
case AEXPR_OR:
|
||||
@@ -276,8 +276,8 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
rexpr = coerce_to_boolean(pstate, rexpr, "OR");
|
||||
|
||||
result = (Node *) makeBoolExpr(OR_EXPR,
|
||||
list_make2(lexpr,
|
||||
rexpr));
|
||||
list_make2(lexpr,
|
||||
rexpr));
|
||||
}
|
||||
break;
|
||||
case AEXPR_NOT:
|
||||
@@ -288,7 +288,7 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
rexpr = coerce_to_boolean(pstate, rexpr, "NOT");
|
||||
|
||||
result = (Node *) makeBoolExpr(NOT_EXPR,
|
||||
list_make1(rexpr));
|
||||
list_make1(rexpr));
|
||||
}
|
||||
break;
|
||||
case AEXPR_OP_ANY:
|
||||
@@ -329,7 +329,7 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
{
|
||||
/* "row op row" */
|
||||
result = make_row_distinct_op(pstate, a->name,
|
||||
lexpr, rexpr);
|
||||
lexpr, rexpr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -338,7 +338,7 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
rexpr = transformExpr(pstate, rexpr);
|
||||
|
||||
result = (Node *) make_distinct_op(pstate,
|
||||
a->name,
|
||||
a->name,
|
||||
lexpr,
|
||||
rexpr);
|
||||
}
|
||||
@@ -420,8 +420,8 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
* copy and then transform-in-place to avoid O(N^2)
|
||||
* behavior from repeated lappend's.
|
||||
*
|
||||
* XXX: repeated lappend() would no longer result in
|
||||
* O(n^2) behavior; worth reconsidering this design?
|
||||
* XXX: repeated lappend() would no longer result in O(n^2)
|
||||
* behavior; worth reconsidering this design?
|
||||
*/
|
||||
targs = list_copy(fn->args);
|
||||
foreach(args, targs)
|
||||
@@ -480,10 +480,10 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
* (ignoring resjunk targets).
|
||||
*/
|
||||
if (tlist_item == NULL ||
|
||||
((TargetEntry *) lfirst(tlist_item))->resdom->resjunk)
|
||||
((TargetEntry *) lfirst(tlist_item))->resdom->resjunk)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("subquery must return a column")));
|
||||
errmsg("subquery must return a column")));
|
||||
while ((tlist_item = lnext(tlist_item)) != NULL)
|
||||
{
|
||||
if (!((TargetEntry *) lfirst(tlist_item))->resdom->resjunk)
|
||||
@@ -573,7 +573,7 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
if (ll_item == NULL)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("subquery has too many columns")));
|
||||
errmsg("subquery has too many columns")));
|
||||
lexpr = lfirst(ll_item);
|
||||
ll_item = lnext(ll_item);
|
||||
|
||||
@@ -611,7 +611,7 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
if (ll_item != NULL)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("subquery has too few columns")));
|
||||
errmsg("subquery has too few columns")));
|
||||
|
||||
if (needNot)
|
||||
{
|
||||
@@ -673,7 +673,7 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
{
|
||||
/* shorthand form was specified, so expand... */
|
||||
warg = (Node *) makeSimpleA_Expr(AEXPR_OP, "=",
|
||||
(Node *) placeholder,
|
||||
(Node *) placeholder,
|
||||
warg);
|
||||
}
|
||||
neww->expr = (Expr *) transformExpr(pstate, warg);
|
||||
@@ -805,8 +805,8 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
|
||||
case T_RowExpr:
|
||||
{
|
||||
RowExpr *r = (RowExpr *) expr;
|
||||
RowExpr *newr = makeNode(RowExpr);
|
||||
RowExpr *r = (RowExpr *) expr;
|
||||
RowExpr *newr = makeNode(RowExpr);
|
||||
List *newargs = NIL;
|
||||
ListCell *arg;
|
||||
|
||||
@@ -967,17 +967,15 @@ transformIndirection(ParseState *pstate, Node *basenode, List *indirection)
|
||||
|
||||
/*
|
||||
* We have to split any field-selection operations apart from
|
||||
* subscripting. Adjacent A_Indices nodes have to be treated
|
||||
* as a single multidimensional subscript operation.
|
||||
* subscripting. Adjacent A_Indices nodes have to be treated as a
|
||||
* single multidimensional subscript operation.
|
||||
*/
|
||||
foreach(i, indirection)
|
||||
{
|
||||
Node *n = lfirst(i);
|
||||
Node *n = lfirst(i);
|
||||
|
||||
if (IsA(n, A_Indices))
|
||||
{
|
||||
subscripts = lappend(subscripts, n);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert(IsA(n, String));
|
||||
@@ -986,7 +984,7 @@ transformIndirection(ParseState *pstate, Node *basenode, List *indirection)
|
||||
if (subscripts)
|
||||
result = (Node *) transformArraySubscripts(pstate,
|
||||
result,
|
||||
exprType(result),
|
||||
exprType(result),
|
||||
InvalidOid,
|
||||
-1,
|
||||
subscripts,
|
||||
@@ -1069,9 +1067,9 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to find the name as a relation. Note that only
|
||||
* relations already entered into the rangetable will be
|
||||
* recognized.
|
||||
* Try to find the name as a relation. Note that only
|
||||
* relations already entered into the rangetable will
|
||||
* be recognized.
|
||||
*
|
||||
* This is a hack for backwards compatibility with
|
||||
* PostQUEL-inspired syntax. The preferred form now
|
||||
@@ -1111,7 +1109,7 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
|
||||
*/
|
||||
node = transformWholeRowRef(pstate, NULL, name1);
|
||||
node = ParseFuncOrColumn(pstate,
|
||||
list_make1(makeString(name2)),
|
||||
list_make1(makeString(name2)),
|
||||
list_make1(node),
|
||||
false, false, true);
|
||||
}
|
||||
@@ -1137,7 +1135,7 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
|
||||
/* Try it as a function call */
|
||||
node = transformWholeRowRef(pstate, name1, name2);
|
||||
node = ParseFuncOrColumn(pstate,
|
||||
list_make1(makeString(name3)),
|
||||
list_make1(makeString(name3)),
|
||||
list_make1(node),
|
||||
false, false, true);
|
||||
}
|
||||
@@ -1173,7 +1171,7 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
|
||||
/* Try it as a function call */
|
||||
node = transformWholeRowRef(pstate, name2, name3);
|
||||
node = ParseFuncOrColumn(pstate,
|
||||
list_make1(makeString(name4)),
|
||||
list_make1(makeString(name4)),
|
||||
list_make1(node),
|
||||
false, false, true);
|
||||
}
|
||||
@@ -1262,11 +1260,12 @@ transformWholeRowRef(ParseState *pstate, char *schemaname, char *relname)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
/*
|
||||
* RTE is a join or subselect. We represent this as a whole-row
|
||||
* Var of RECORD type. (Note that in most cases the Var will
|
||||
* be expanded to a RowExpr during planning, but that is not
|
||||
* our concern here.)
|
||||
* RTE is a join or subselect. We represent this as a
|
||||
* whole-row Var of RECORD type. (Note that in most cases the
|
||||
* Var will be expanded to a RowExpr during planning, but that
|
||||
* is not our concern here.)
|
||||
*/
|
||||
result = (Node *) makeVar(vnum,
|
||||
InvalidAttrNumber,
|
||||
@@ -1666,7 +1665,7 @@ static Node *
|
||||
make_row_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree)
|
||||
{
|
||||
Node *result = NULL;
|
||||
RowExpr *lrow,
|
||||
RowExpr *lrow,
|
||||
*rrow;
|
||||
List *largs,
|
||||
*rargs;
|
||||
@@ -1700,27 +1699,23 @@ make_row_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree)
|
||||
(strcmp(oprname, "<=") == 0) ||
|
||||
(strcmp(oprname, ">") == 0) ||
|
||||
(strcmp(oprname, ">=") == 0))
|
||||
{
|
||||
boolop = AND_EXPR;
|
||||
}
|
||||
else if (strcmp(oprname, "<>") == 0)
|
||||
{
|
||||
boolop = OR_EXPR;
|
||||
}
|
||||
else
|
||||
{
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("operator %s is not supported for row expressions",
|
||||
oprname)));
|
||||
boolop = 0; /* keep compiler quiet */
|
||||
errmsg("operator %s is not supported for row expressions",
|
||||
oprname)));
|
||||
boolop = 0; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
forboth(l, largs, r, rargs)
|
||||
{
|
||||
Node *larg = (Node *) lfirst(l);
|
||||
Node *rarg = (Node *) lfirst(r);
|
||||
Node *cmp;
|
||||
Node *larg = (Node *) lfirst(l);
|
||||
Node *rarg = (Node *) lfirst(r);
|
||||
Node *cmp;
|
||||
|
||||
cmp = (Node *) make_op(pstate, opname, larg, rarg);
|
||||
cmp = coerce_to_boolean(pstate, cmp, "row comparison");
|
||||
@@ -1751,7 +1746,7 @@ make_row_distinct_op(ParseState *pstate, List *opname,
|
||||
Node *ltree, Node *rtree)
|
||||
{
|
||||
Node *result = NULL;
|
||||
RowExpr *lrow,
|
||||
RowExpr *lrow,
|
||||
*rrow;
|
||||
List *largs,
|
||||
*rargs;
|
||||
@@ -1773,9 +1768,9 @@ make_row_distinct_op(ParseState *pstate, List *opname,
|
||||
|
||||
forboth(l, largs, r, rargs)
|
||||
{
|
||||
Node *larg = (Node *) lfirst(l);
|
||||
Node *rarg = (Node *) lfirst(r);
|
||||
Node *cmp;
|
||||
Node *larg = (Node *) lfirst(l);
|
||||
Node *rarg = (Node *) lfirst(r);
|
||||
Node *cmp;
|
||||
|
||||
cmp = (Node *) make_distinct_op(pstate, opname, larg, rarg);
|
||||
if (result == NULL)
|
||||
@@ -1800,16 +1795,16 @@ make_row_distinct_op(ParseState *pstate, List *opname,
|
||||
static Expr *
|
||||
make_distinct_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree)
|
||||
{
|
||||
Expr *result;
|
||||
Expr *result;
|
||||
|
||||
result = make_op(pstate, opname, ltree, rtree);
|
||||
if (((OpExpr *) result)->opresulttype != BOOLOID)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("IS DISTINCT FROM requires = operator to yield boolean")));
|
||||
errmsg("IS DISTINCT FROM requires = operator to yield boolean")));
|
||||
|
||||
/*
|
||||
* We rely on DistinctExpr and OpExpr being
|
||||
* same struct
|
||||
* We rely on DistinctExpr and OpExpr being same struct
|
||||
*/
|
||||
NodeSetTag(result, T_DistinctExpr);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.173 2004/08/29 04:12:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.174 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
|
||||
static Node *ParseComplexProjection(ParseState *pstate, char *funcname,
|
||||
Node *first_arg);
|
||||
Node *first_arg);
|
||||
static Oid **argtype_inherit(int nargs, Oid *argtypes);
|
||||
|
||||
static int find_inheritors(Oid relid, Oid **supervec);
|
||||
@@ -111,9 +111,10 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
||||
first_arg);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
/*
|
||||
* If ParseComplexProjection doesn't recognize it as a projection,
|
||||
* just press on.
|
||||
* If ParseComplexProjection doesn't recognize it as a
|
||||
* projection, just press on.
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -203,7 +204,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
||||
func_signature_string(funcname, nargs,
|
||||
actual_arg_types)),
|
||||
errhint("No function matches the given name and argument types. "
|
||||
"You may need to add explicit type casts.")));
|
||||
"You may need to add explicit type casts.")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -902,8 +903,7 @@ find_inheritors(Oid relid, Oid **supervec)
|
||||
ListCell *queue_item;
|
||||
|
||||
/*
|
||||
* Begin the search at the relation itself, so add relid to the
|
||||
* queue.
|
||||
* Begin the search at the relation itself, so add relid to the queue.
|
||||
*/
|
||||
queue = list_make1_oid(relid);
|
||||
visited = NIL;
|
||||
@@ -911,18 +911,18 @@ find_inheritors(Oid relid, Oid **supervec)
|
||||
inhrel = heap_openr(InheritsRelationName, AccessShareLock);
|
||||
|
||||
/*
|
||||
* Use queue to do a breadth-first traversal of the inheritance
|
||||
* graph from the relid supplied up to the root. Notice that we
|
||||
* append to the queue inside the loop --- this is okay because
|
||||
* the foreach() macro doesn't advance queue_item until the next
|
||||
* loop iteration begins.
|
||||
* Use queue to do a breadth-first traversal of the inheritance graph
|
||||
* from the relid supplied up to the root. Notice that we append to
|
||||
* the queue inside the loop --- this is okay because the foreach()
|
||||
* macro doesn't advance queue_item until the next loop iteration
|
||||
* begins.
|
||||
*/
|
||||
foreach(queue_item, queue)
|
||||
{
|
||||
Oid this_relid = lfirst_oid(queue_item);
|
||||
ScanKeyData skey;
|
||||
HeapScanDesc inhscan;
|
||||
HeapTuple inhtup;
|
||||
Oid this_relid = lfirst_oid(queue_item);
|
||||
ScanKeyData skey;
|
||||
HeapScanDesc inhscan;
|
||||
HeapTuple inhtup;
|
||||
|
||||
/* If we've seen this relid already, skip it */
|
||||
if (list_member_oid(visited, this_relid))
|
||||
@@ -931,8 +931,8 @@ find_inheritors(Oid relid, Oid **supervec)
|
||||
/*
|
||||
* Okay, this is a not-yet-seen relid. Add it to the list of
|
||||
* already-visited OIDs, then find all the types this relid
|
||||
* inherits from and add them to the queue. The one exception
|
||||
* is we don't add the original relation to 'visited'.
|
||||
* inherits from and add them to the queue. The one exception is
|
||||
* we don't add the original relation to 'visited'.
|
||||
*/
|
||||
if (queue_item != list_head(queue))
|
||||
visited = lappend_oid(visited, this_relid);
|
||||
@@ -1146,10 +1146,10 @@ ParseComplexProjection(ParseState *pstate, char *funcname, Node *first_arg)
|
||||
|
||||
/*
|
||||
* Special case for whole-row Vars so that we can resolve (foo.*).bar
|
||||
* even when foo is a reference to a subselect, join, or RECORD function.
|
||||
* A bonus is that we avoid generating an unnecessary FieldSelect; our
|
||||
* result can omit the whole-row Var and just be a Var for the selected
|
||||
* field.
|
||||
* even when foo is a reference to a subselect, join, or RECORD
|
||||
* function. A bonus is that we avoid generating an unnecessary
|
||||
* FieldSelect; our result can omit the whole-row Var and just be a
|
||||
* Var for the selected field.
|
||||
*/
|
||||
if (IsA(first_arg, Var) &&
|
||||
((Var *) first_arg)->varattno == InvalidAttrNumber)
|
||||
@@ -1221,8 +1221,8 @@ unknown_attribute(ParseState *pstate, Node *relref, char *attname)
|
||||
else if (relTypeId == RECORDOID)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("could not identify column \"%s\" in record data type",
|
||||
attname)));
|
||||
errmsg("could not identify column \"%s\" in record data type",
|
||||
attname)));
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.85 2004/08/29 04:12:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.86 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -148,8 +148,8 @@ transformArraySubscripts(ParseState *pstate,
|
||||
* element. If any of the items are double subscripts (lower:upper),
|
||||
* then the subscript expression means an array slice operation. In
|
||||
* this case, we supply a default lower bound of 1 for any items that
|
||||
* contain only a single subscript. We have to prescan the indirection
|
||||
* list to see if there are any double subscripts.
|
||||
* contain only a single subscript. We have to prescan the
|
||||
* indirection list to see if there are any double subscripts.
|
||||
*/
|
||||
foreach(idx, indirection)
|
||||
{
|
||||
@@ -224,7 +224,8 @@ transformArraySubscripts(ParseState *pstate,
|
||||
|
||||
/*
|
||||
* If doing an array store, coerce the source value to the right type.
|
||||
* (This should agree with the coercion done by updateTargetListEntry.)
|
||||
* (This should agree with the coercion done by
|
||||
* updateTargetListEntry.)
|
||||
*/
|
||||
if (assignFrom != NULL)
|
||||
{
|
||||
@@ -243,7 +244,7 @@ transformArraySubscripts(ParseState *pstate,
|
||||
" but expression is of type %s",
|
||||
format_type_be(typeneeded),
|
||||
format_type_be(typesource)),
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_oper.c,v 1.79 2004/08/29 04:12:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_oper.c,v 1.80 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -141,8 +141,8 @@ equality_oper(Oid argtype, bool noError)
|
||||
Operator optup;
|
||||
|
||||
/*
|
||||
* Look for an "=" operator for the datatype. We require it to be
|
||||
* an exact or binary-compatible match, since most callers are not
|
||||
* Look for an "=" operator for the datatype. We require it to be an
|
||||
* exact or binary-compatible match, since most callers are not
|
||||
* prepared to cope with adding any run-time type coercion steps.
|
||||
*/
|
||||
typentry = lookup_type_cache(argtype, TYPECACHE_EQ_OPR);
|
||||
@@ -155,7 +155,7 @@ equality_oper(Oid argtype, bool noError)
|
||||
*/
|
||||
if (oproid == ARRAY_EQ_OP)
|
||||
{
|
||||
Oid elem_type = get_element_type(argtype);
|
||||
Oid elem_type = get_element_type(argtype);
|
||||
|
||||
if (OidIsValid(elem_type))
|
||||
{
|
||||
@@ -166,7 +166,7 @@ equality_oper(Oid argtype, bool noError)
|
||||
oproid = InvalidOid; /* element type has no "=" */
|
||||
}
|
||||
else
|
||||
oproid = InvalidOid; /* bogus array type? */
|
||||
oproid = InvalidOid; /* bogus array type? */
|
||||
}
|
||||
|
||||
if (OidIsValid(oproid))
|
||||
@@ -200,14 +200,14 @@ ordering_oper(Oid argtype, bool noError)
|
||||
Operator optup;
|
||||
|
||||
/*
|
||||
* Look for a "<" operator for the datatype. We require it to be
|
||||
* an exact or binary-compatible match, since most callers are not
|
||||
* Look for a "<" operator for the datatype. We require it to be an
|
||||
* exact or binary-compatible match, since most callers are not
|
||||
* prepared to cope with adding any run-time type coercion steps.
|
||||
*
|
||||
* Note: the search algorithm used by typcache.c ensures that if a "<"
|
||||
* operator is returned, it will be consistent with the "=" operator
|
||||
* returned by equality_oper. This is critical for sorting and grouping
|
||||
* purposes.
|
||||
* returned by equality_oper. This is critical for sorting and
|
||||
* grouping purposes.
|
||||
*/
|
||||
typentry = lookup_type_cache(argtype, TYPECACHE_LT_OPR);
|
||||
oproid = typentry->lt_opr;
|
||||
@@ -219,7 +219,7 @@ ordering_oper(Oid argtype, bool noError)
|
||||
*/
|
||||
if (oproid == ARRAY_LT_OP)
|
||||
{
|
||||
Oid elem_type = get_element_type(argtype);
|
||||
Oid elem_type = get_element_type(argtype);
|
||||
|
||||
if (OidIsValid(elem_type))
|
||||
{
|
||||
@@ -230,7 +230,7 @@ ordering_oper(Oid argtype, bool noError)
|
||||
oproid = InvalidOid; /* element type has no "<" */
|
||||
}
|
||||
else
|
||||
oproid = InvalidOid; /* bogus array type? */
|
||||
oproid = InvalidOid; /* bogus array type? */
|
||||
}
|
||||
|
||||
if (OidIsValid(oproid))
|
||||
@@ -265,14 +265,14 @@ reverse_ordering_oper(Oid argtype, bool noError)
|
||||
Operator optup;
|
||||
|
||||
/*
|
||||
* Look for a ">" operator for the datatype. We require it to be
|
||||
* an exact or binary-compatible match, since most callers are not
|
||||
* Look for a ">" operator for the datatype. We require it to be an
|
||||
* exact or binary-compatible match, since most callers are not
|
||||
* prepared to cope with adding any run-time type coercion steps.
|
||||
*
|
||||
* Note: the search algorithm used by typcache.c ensures that if a ">"
|
||||
* operator is returned, it will be consistent with the "=" operator
|
||||
* returned by equality_oper. This is critical for sorting and grouping
|
||||
* purposes.
|
||||
* returned by equality_oper. This is critical for sorting and
|
||||
* grouping purposes.
|
||||
*/
|
||||
typentry = lookup_type_cache(argtype, TYPECACHE_GT_OPR);
|
||||
oproid = typentry->gt_opr;
|
||||
@@ -284,7 +284,7 @@ reverse_ordering_oper(Oid argtype, bool noError)
|
||||
*/
|
||||
if (oproid == ARRAY_GT_OP)
|
||||
{
|
||||
Oid elem_type = get_element_type(argtype);
|
||||
Oid elem_type = get_element_type(argtype);
|
||||
|
||||
if (OidIsValid(elem_type))
|
||||
{
|
||||
@@ -295,7 +295,7 @@ reverse_ordering_oper(Oid argtype, bool noError)
|
||||
oproid = InvalidOid; /* element type has no ">" */
|
||||
}
|
||||
else
|
||||
oproid = InvalidOid; /* bogus array type? */
|
||||
oproid = InvalidOid; /* bogus array type? */
|
||||
}
|
||||
|
||||
if (OidIsValid(oproid))
|
||||
@@ -394,7 +394,7 @@ static Oid
|
||||
binary_oper_exact(Oid arg1, Oid arg2,
|
||||
FuncCandidateList candidates)
|
||||
{
|
||||
FuncCandidateList cand;
|
||||
FuncCandidateList cand;
|
||||
bool was_unknown = false;
|
||||
|
||||
/* Unspecified type for one of the arguments? then use the other */
|
||||
@@ -418,7 +418,7 @@ binary_oper_exact(Oid arg1, Oid arg2,
|
||||
if (was_unknown)
|
||||
{
|
||||
/* arg1 and arg2 are the same here, need only look at arg1 */
|
||||
Oid basetype = getBaseType(arg1);
|
||||
Oid basetype = getBaseType(arg1);
|
||||
|
||||
if (basetype != arg1)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.99 2004/08/29 04:12:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.100 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -43,9 +43,9 @@ static void scanNameSpaceForConflict(ParseState *pstate, Node *nsnode,
|
||||
RangeTblEntry *rte1, const char *aliasname1);
|
||||
static bool isForUpdate(ParseState *pstate, char *refname);
|
||||
static void expandRelation(Oid relid, Alias *eref,
|
||||
int rtindex, int sublevels_up,
|
||||
bool include_dropped,
|
||||
List **colnames, List **colvars);
|
||||
int rtindex, int sublevels_up,
|
||||
bool include_dropped,
|
||||
List **colnames, List **colvars);
|
||||
static int specialAttNum(const char *attname);
|
||||
static void warnAutoRange(ParseState *pstate, RangeVar *relation);
|
||||
|
||||
@@ -142,7 +142,7 @@ scanNameSpaceForRefname(ParseState *pstate, Node *nsnode,
|
||||
return NULL;
|
||||
if (IsA(nsnode, RangeTblRef))
|
||||
{
|
||||
int varno = ((RangeTblRef *) nsnode)->rtindex;
|
||||
int varno = ((RangeTblRef *) nsnode)->rtindex;
|
||||
RangeTblEntry *rte = rt_fetch(varno, pstate->p_rtable);
|
||||
|
||||
if (strcmp(rte->eref->aliasname, refname) == 0)
|
||||
@@ -489,14 +489,15 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname)
|
||||
* Scan the user column names (or aliases) for a match. Complain if
|
||||
* multiple matches.
|
||||
*
|
||||
* Note: eref->colnames may include entries for dropped columns,
|
||||
* but those will be empty strings that cannot match any legal SQL
|
||||
* Note: eref->colnames may include entries for dropped columns, but
|
||||
* those will be empty strings that cannot match any legal SQL
|
||||
* identifier, so we don't bother to test for that case here.
|
||||
*
|
||||
* Should this somehow go wrong and we try to access a dropped column,
|
||||
* we'll still catch it by virtue of the checks in
|
||||
* get_rte_attribute_type(), which is called by make_var(). That routine
|
||||
* has to do a cache lookup anyway, so the check there is cheap.
|
||||
* get_rte_attribute_type(), which is called by make_var(). That
|
||||
* routine has to do a cache lookup anyway, so the check there is
|
||||
* cheap.
|
||||
*/
|
||||
foreach(c, rte->eref->colnames)
|
||||
{
|
||||
@@ -723,7 +724,7 @@ buildRelationAliases(TupleDesc tupdesc, Alias *alias, Alias *eref)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("table \"%s\" has %d columns available but %d columns specified",
|
||||
eref->aliasname, maxattrs - numdropped, numaliases)));
|
||||
eref->aliasname, maxattrs - numdropped, numaliases)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -761,8 +762,8 @@ addRangeTableEntry(ParseState *pstate,
|
||||
rte->relid = RelationGetRelid(rel);
|
||||
|
||||
/*
|
||||
* Build the list of effective column names using user-supplied aliases
|
||||
* and/or actual column names.
|
||||
* Build the list of effective column names using user-supplied
|
||||
* aliases and/or actual column names.
|
||||
*/
|
||||
rte->eref = makeAlias(refname, NIL);
|
||||
buildRelationAliases(rel->rd_att, alias, rte->eref);
|
||||
@@ -788,7 +789,7 @@ addRangeTableEntry(ParseState *pstate,
|
||||
rte->inFromCl = inFromCl;
|
||||
|
||||
rte->requiredPerms = ACL_SELECT;
|
||||
rte->checkAsUser = 0; /* not set-uid by default, either */
|
||||
rte->checkAsUser = 0; /* not set-uid by default, either */
|
||||
|
||||
/*
|
||||
* Add completed RTE to pstate's range table list, but not to join
|
||||
@@ -834,8 +835,8 @@ addRangeTableEntryForRelation(ParseState *pstate,
|
||||
rte->relid = relid;
|
||||
|
||||
/*
|
||||
* Build the list of effective column names using user-supplied aliases
|
||||
* and/or actual column names.
|
||||
* Build the list of effective column names using user-supplied
|
||||
* aliases and/or actual column names.
|
||||
*/
|
||||
rte->eref = makeAlias(refname, NIL);
|
||||
buildRelationAliases(rel->rd_att, alias, rte->eref);
|
||||
@@ -861,7 +862,7 @@ addRangeTableEntryForRelation(ParseState *pstate,
|
||||
rte->inFromCl = inFromCl;
|
||||
|
||||
rte->requiredPerms = ACL_SELECT;
|
||||
rte->checkAsUser = 0; /* not set-uid by default, either */
|
||||
rte->checkAsUser = 0; /* not set-uid by default, either */
|
||||
|
||||
/*
|
||||
* Add completed RTE to pstate's range table list, but not to join
|
||||
@@ -1131,7 +1132,7 @@ addRangeTableEntryForJoin(ParseState *pstate,
|
||||
/* fill in any unspecified alias columns */
|
||||
if (numaliases < list_length(colnames))
|
||||
eref->colnames = list_concat(eref->colnames,
|
||||
list_copy_tail(colnames, numaliases));
|
||||
list_copy_tail(colnames, numaliases));
|
||||
|
||||
rte->eref = eref;
|
||||
|
||||
@@ -1273,8 +1274,8 @@ expandRTE(List *rtable, int rtindex, int sublevels_up,
|
||||
case RTE_SUBQUERY:
|
||||
{
|
||||
/* Subquery RTE */
|
||||
ListCell *aliasp_item = list_head(rte->eref->colnames);
|
||||
ListCell *tlistitem;
|
||||
ListCell *aliasp_item = list_head(rte->eref->colnames);
|
||||
ListCell *tlistitem;
|
||||
|
||||
varattno = 0;
|
||||
foreach(tlistitem, rte->subquery->targetList)
|
||||
@@ -1338,7 +1339,7 @@ expandRTE(List *rtable, int rtindex, int sublevels_up,
|
||||
*/
|
||||
if (colnames)
|
||||
*colnames = lappend(*colnames,
|
||||
linitial(rte->eref->colnames));
|
||||
linitial(rte->eref->colnames));
|
||||
|
||||
if (colvars)
|
||||
{
|
||||
@@ -1396,13 +1397,13 @@ expandRTE(List *rtable, int rtindex, int sublevels_up,
|
||||
case RTE_JOIN:
|
||||
{
|
||||
/* Join RTE */
|
||||
ListCell *colname;
|
||||
ListCell *aliasvar;
|
||||
ListCell *colname;
|
||||
ListCell *aliasvar;
|
||||
|
||||
Assert(list_length(rte->eref->colnames) == list_length(rte->joinaliasvars));
|
||||
|
||||
varattno = 0;
|
||||
forboth (colname, rte->eref->colnames, aliasvar, rte->joinaliasvars)
|
||||
forboth(colname, rte->eref->colnames, aliasvar, rte->joinaliasvars)
|
||||
{
|
||||
varattno++;
|
||||
|
||||
@@ -1420,16 +1421,16 @@ expandRTE(List *rtable, int rtindex, int sublevels_up,
|
||||
{
|
||||
if (colnames)
|
||||
*colnames = lappend(*colnames,
|
||||
makeString(pstrdup("")));
|
||||
makeString(pstrdup("")));
|
||||
if (colvars)
|
||||
{
|
||||
/*
|
||||
* can't use atttypid here, but it doesn't
|
||||
* really matter what type the Const claims to
|
||||
* be.
|
||||
* really matter what type the Const
|
||||
* claims to be.
|
||||
*/
|
||||
*colvars = lappend(*colvars,
|
||||
makeNullConst(INT4OID));
|
||||
makeNullConst(INT4OID));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@@ -1493,8 +1494,8 @@ expandRelation(Oid relid, Alias *eref, int rtindex, int sublevels_up,
|
||||
if (colvars)
|
||||
{
|
||||
/*
|
||||
* can't use atttypid here, but it doesn't really matter
|
||||
* what type the Const claims to be.
|
||||
* can't use atttypid here, but it doesn't really
|
||||
* matter what type the Const claims to be.
|
||||
*/
|
||||
*colvars = lappend(*colvars, makeNullConst(INT4OID));
|
||||
}
|
||||
@@ -1559,7 +1560,8 @@ expandRelAttrs(ParseState *pstate, List *rtable, int rtindex, int sublevels_up)
|
||||
te_list = lappend(te_list, te);
|
||||
}
|
||||
|
||||
Assert(name == NULL && var == NULL); /* lists not the same length? */
|
||||
Assert(name == NULL && var == NULL); /* lists not the same
|
||||
* length? */
|
||||
|
||||
return te_list;
|
||||
}
|
||||
@@ -1761,7 +1763,10 @@ get_rte_attribute_is_dropped(List *rtable, int rtindex, AttrNumber attnum)
|
||||
{
|
||||
case RTE_RELATION:
|
||||
{
|
||||
/* Plain relation RTE --- get the attribute's catalog entry */
|
||||
/*
|
||||
* Plain relation RTE --- get the attribute's catalog
|
||||
* entry
|
||||
*/
|
||||
HeapTuple tp;
|
||||
Form_pg_attribute att_tup;
|
||||
|
||||
@@ -1784,18 +1789,20 @@ get_rte_attribute_is_dropped(List *rtable, int rtindex, AttrNumber attnum)
|
||||
case RTE_JOIN:
|
||||
{
|
||||
/*
|
||||
* A join RTE would not have dropped columns when constructed,
|
||||
* but one in a stored rule might contain columns that were
|
||||
* dropped from the underlying tables, if said columns are
|
||||
* nowhere explicitly referenced in the rule. So we have to
|
||||
* recursively look at the referenced column.
|
||||
* A join RTE would not have dropped columns when
|
||||
* constructed, but one in a stored rule might contain
|
||||
* columns that were dropped from the underlying tables,
|
||||
* if said columns are nowhere explicitly referenced in
|
||||
* the rule. So we have to recursively look at the
|
||||
* referenced column.
|
||||
*/
|
||||
Var *aliasvar;
|
||||
Var *aliasvar;
|
||||
|
||||
if (attnum <= 0 ||
|
||||
attnum > list_length(rte->joinaliasvars))
|
||||
elog(ERROR, "invalid varattno %d", attnum);
|
||||
aliasvar = (Var *) list_nth(rte->joinaliasvars, attnum - 1);
|
||||
|
||||
/*
|
||||
* If the list item isn't a simple Var, then it must
|
||||
* represent a merged column, ie a USING column, and so it
|
||||
@@ -1807,7 +1814,7 @@ get_rte_attribute_is_dropped(List *rtable, int rtindex, AttrNumber attnum)
|
||||
else
|
||||
result = get_rte_attribute_is_dropped(rtable,
|
||||
aliasvar->varno,
|
||||
aliasvar->varattno);
|
||||
aliasvar->varattno);
|
||||
}
|
||||
break;
|
||||
case RTE_FUNCTION:
|
||||
@@ -1865,7 +1872,7 @@ get_rte_attribute_is_dropped(List *rtable, int rtindex, AttrNumber attnum)
|
||||
TargetEntry *
|
||||
get_tle_by_resno(List *tlist, AttrNumber resno)
|
||||
{
|
||||
ListCell *l;
|
||||
ListCell *l;
|
||||
|
||||
foreach(l, tlist)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.124 2004/08/29 04:12:42 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.125 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -113,8 +113,8 @@ transformTargetList(ParseState *pstate, List *targetlist)
|
||||
|
||||
/*
|
||||
* Check for "something.*". Depending on the complexity of the
|
||||
* "something", the star could appear as the last name in ColumnRef,
|
||||
* or as the last indirection item in A_Indirection.
|
||||
* "something", the star could appear as the last name in
|
||||
* ColumnRef, or as the last indirection item in A_Indirection.
|
||||
*/
|
||||
if (IsA(res->val, ColumnRef))
|
||||
{
|
||||
@@ -130,15 +130,15 @@ transformTargetList(ParseState *pstate, List *targetlist)
|
||||
}
|
||||
else if (IsA(res->val, A_Indirection))
|
||||
{
|
||||
A_Indirection *ind = (A_Indirection *) res->val;
|
||||
Node *lastitem = llast(ind->indirection);
|
||||
A_Indirection *ind = (A_Indirection *) res->val;
|
||||
Node *lastitem = llast(ind->indirection);
|
||||
|
||||
if (IsA(lastitem, String) &&
|
||||
strcmp(strVal(lastitem), "*") == 0)
|
||||
{
|
||||
/* It is something.*, expand into multiple items */
|
||||
p_target = list_concat(p_target,
|
||||
ExpandIndirectionStar(pstate, ind));
|
||||
ExpandIndirectionStar(pstate, ind));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -290,7 +290,7 @@ updateTargetListEntry(ParseState *pstate,
|
||||
if (IsA(linitial(indirection), A_Indices))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot set an array element to DEFAULT")));
|
||||
errmsg("cannot set an array element to DEFAULT")));
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
@@ -303,9 +303,9 @@ updateTargetListEntry(ParseState *pstate,
|
||||
|
||||
/*
|
||||
* If there is indirection on the target column, prepare an array or
|
||||
* subfield assignment expression. This will generate a new column value
|
||||
* that the source value has been inserted into, which can then be placed
|
||||
* in the new tuple constructed by INSERT or UPDATE.
|
||||
* subfield assignment expression. This will generate a new column
|
||||
* value that the source value has been inserted into, which can then
|
||||
* be placed in the new tuple constructed by INSERT or UPDATE.
|
||||
*/
|
||||
if (indirection)
|
||||
{
|
||||
@@ -314,9 +314,9 @@ updateTargetListEntry(ParseState *pstate,
|
||||
if (pstate->p_is_insert)
|
||||
{
|
||||
/*
|
||||
* The command is INSERT INTO table (col.something) ...
|
||||
* so there is not really a source value to work with.
|
||||
* Insert a NULL constant as the source value.
|
||||
* The command is INSERT INTO table (col.something) ... so
|
||||
* there is not really a source value to work with. Insert a
|
||||
* NULL constant as the source value.
|
||||
*/
|
||||
colVar = (Node *) makeNullConst(attrtype);
|
||||
}
|
||||
@@ -360,7 +360,7 @@ updateTargetListEntry(ParseState *pstate,
|
||||
colname,
|
||||
format_type_be(attrtype),
|
||||
format_type_be(type_id)),
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -369,9 +369,10 @@ updateTargetListEntry(ParseState *pstate,
|
||||
*/
|
||||
resnode->restype = attrtype;
|
||||
resnode->restypmod = attrtypmod;
|
||||
|
||||
/*
|
||||
* Set the resno to identify the target column --- the rewriter and
|
||||
* planner depend on this. We also set the resname to identify the
|
||||
* planner depend on this. We also set the resname to identify the
|
||||
* target column, but this is only for debugging purposes; it should
|
||||
* not be relied on. (In particular, it might be out of date in a
|
||||
* stored rule.)
|
||||
@@ -432,12 +433,12 @@ transformAssignmentIndirection(ParseState *pstate,
|
||||
|
||||
/*
|
||||
* We have to split any field-selection operations apart from
|
||||
* subscripting. Adjacent A_Indices nodes have to be treated
|
||||
* as a single multidimensional subscript operation.
|
||||
* subscripting. Adjacent A_Indices nodes have to be treated as a
|
||||
* single multidimensional subscript operation.
|
||||
*/
|
||||
for_each_cell(i, indirection)
|
||||
{
|
||||
Node *n = lfirst(i);
|
||||
Node *n = lfirst(i);
|
||||
|
||||
if (IsA(n, A_Indices))
|
||||
{
|
||||
@@ -448,18 +449,18 @@ transformAssignmentIndirection(ParseState *pstate,
|
||||
else
|
||||
{
|
||||
FieldStore *fstore;
|
||||
Oid typrelid;
|
||||
AttrNumber attnum;
|
||||
Oid fieldTypeId;
|
||||
int32 fieldTypMod;
|
||||
Oid typrelid;
|
||||
AttrNumber attnum;
|
||||
Oid fieldTypeId;
|
||||
int32 fieldTypMod;
|
||||
|
||||
Assert(IsA(n, String));
|
||||
|
||||
/* process subscripts before this field selection */
|
||||
if (subscripts)
|
||||
{
|
||||
Oid elementTypeId = transformArrayType(targetTypeId);
|
||||
Oid typeNeeded = isSlice ? targetTypeId : elementTypeId;
|
||||
Oid elementTypeId = transformArrayType(targetTypeId);
|
||||
Oid typeNeeded = isSlice ? targetTypeId : elementTypeId;
|
||||
|
||||
/* recurse to create appropriate RHS for array assign */
|
||||
rhs = transformAssignmentIndirection(pstate,
|
||||
@@ -494,7 +495,7 @@ transformAssignmentIndirection(ParseState *pstate,
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("column \"%s\" not found in data type %s",
|
||||
strVal(n), format_type_be(targetTypeId))));
|
||||
strVal(n), format_type_be(targetTypeId))));
|
||||
if (attnum < 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
@@ -528,8 +529,8 @@ transformAssignmentIndirection(ParseState *pstate,
|
||||
/* process trailing subscripts, if any */
|
||||
if (subscripts)
|
||||
{
|
||||
Oid elementTypeId = transformArrayType(targetTypeId);
|
||||
Oid typeNeeded = isSlice ? targetTypeId : elementTypeId;
|
||||
Oid elementTypeId = transformArrayType(targetTypeId);
|
||||
Oid typeNeeded = isSlice ? targetTypeId : elementTypeId;
|
||||
|
||||
/* recurse to create appropriate RHS for array assign */
|
||||
rhs = transformAssignmentIndirection(pstate,
|
||||
@@ -567,7 +568,7 @@ transformAssignmentIndirection(ParseState *pstate,
|
||||
targetName,
|
||||
format_type_be(targetTypeId),
|
||||
format_type_be(exprType(rhs))),
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
@@ -576,7 +577,7 @@ transformAssignmentIndirection(ParseState *pstate,
|
||||
targetName,
|
||||
format_type_be(targetTypeId),
|
||||
format_type_be(exprType(rhs))),
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -645,8 +646,8 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
|
||||
if (list_member_int(*attrnos, attrno))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_COLUMN),
|
||||
errmsg("column \"%s\" specified more than once",
|
||||
name)));
|
||||
errmsg("column \"%s\" specified more than once",
|
||||
name)));
|
||||
wholecols = lappend_int(wholecols, attrno);
|
||||
}
|
||||
else
|
||||
@@ -655,8 +656,8 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
|
||||
if (list_member_int(wholecols, attrno))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_COLUMN),
|
||||
errmsg("column \"%s\" specified more than once",
|
||||
name)));
|
||||
errmsg("column \"%s\" specified more than once",
|
||||
name)));
|
||||
}
|
||||
|
||||
*attrnos = lappend_int(*attrnos, attrno);
|
||||
@@ -713,22 +714,21 @@ ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref)
|
||||
relname = strVal(lsecond(fields));
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
char *name1 = strVal(linitial(fields));
|
||||
{
|
||||
char *name1 = strVal(linitial(fields));
|
||||
|
||||
/*
|
||||
* We check the catalog name and then ignore
|
||||
* it.
|
||||
*/
|
||||
if (strcmp(name1, get_database_name(MyDatabaseId)) != 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cross-database references are not implemented: %s",
|
||||
NameListToString(fields))));
|
||||
schemaname = strVal(lsecond(fields));
|
||||
relname = strVal(lthird(fields));
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* We check the catalog name and then ignore it.
|
||||
*/
|
||||
if (strcmp(name1, get_database_name(MyDatabaseId)) != 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cross-database references are not implemented: %s",
|
||||
NameListToString(fields))));
|
||||
schemaname = strVal(lsecond(fields));
|
||||
relname = strVal(lthird(fields));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
@@ -780,7 +780,7 @@ ExpandAllTables(ParseState *pstate)
|
||||
else
|
||||
{
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(n));
|
||||
rtindex = 0; /* keep compiler quiet */
|
||||
rtindex = 0; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -923,7 +923,7 @@ FigureColnameInternal(Node *node, char **name)
|
||||
/* find last field name, if any, ignoring "*" */
|
||||
foreach(l, ((ColumnRef *) node)->fields)
|
||||
{
|
||||
Node *i = lfirst(l);
|
||||
Node *i = lfirst(l);
|
||||
|
||||
if (strcmp(strVal(i), "*") != 0)
|
||||
fname = strVal(i);
|
||||
@@ -944,7 +944,7 @@ FigureColnameInternal(Node *node, char **name)
|
||||
/* find last field name, if any, ignoring "*" */
|
||||
foreach(l, ind->indirection)
|
||||
{
|
||||
Node *i = lfirst(l);
|
||||
Node *i = lfirst(l);
|
||||
|
||||
if (IsA(i, String) &&
|
||||
strcmp(strVal(i), "*") != 0)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.70 2004/08/29 04:12:42 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.71 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -91,8 +91,8 @@ LookupTypeName(const TypeName *typename)
|
||||
if (attnum == InvalidAttrNumber)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("column \"%s\" of relation \"%s\" does not exist",
|
||||
field, rel->relname)));
|
||||
errmsg("column \"%s\" of relation \"%s\" does not exist",
|
||||
field, rel->relname)));
|
||||
restype = get_atttype(relid, attnum);
|
||||
|
||||
/* this construct should never have an array indicator */
|
||||
@@ -370,10 +370,11 @@ pts_error_callback(void *arg)
|
||||
const char *str = (const char *) arg;
|
||||
|
||||
errcontext("invalid type name \"%s\"", str);
|
||||
|
||||
/*
|
||||
* Currently we just suppress any syntax error position report,
|
||||
* rather than transforming to an "internal query" error. It's
|
||||
* unlikely that a type name is complex enough to need positioning.
|
||||
* Currently we just suppress any syntax error position report, rather
|
||||
* than transforming to an "internal query" error. It's unlikely that
|
||||
* a type name is complex enough to need positioning.
|
||||
*/
|
||||
errposition(0);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/scansup.c,v 1.27 2004/08/29 04:12:42 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/scansup.c,v 1.28 2004/08/29 05:06:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -133,18 +133,19 @@ downcase_truncate_identifier(const char *ident, int len, bool warn)
|
||||
int i;
|
||||
|
||||
result = palloc(len + 1);
|
||||
|
||||
/*
|
||||
* SQL99 specifies Unicode-aware case normalization, which we don't yet
|
||||
* have the infrastructure for. Instead we use tolower() to provide a
|
||||
* locale-aware translation. However, there are some locales where this
|
||||
* is not right either (eg, Turkish may do strange things with 'i' and
|
||||
* 'I'). Our current compromise is to use tolower() for characters with
|
||||
* the high bit set, and use an ASCII-only downcasing for 7-bit
|
||||
* characters.
|
||||
* SQL99 specifies Unicode-aware case normalization, which we don't
|
||||
* yet have the infrastructure for. Instead we use tolower() to
|
||||
* provide a locale-aware translation. However, there are some
|
||||
* locales where this is not right either (eg, Turkish may do strange
|
||||
* things with 'i' and 'I'). Our current compromise is to use
|
||||
* tolower() for characters with the high bit set, and use an
|
||||
* ASCII-only downcasing for 7-bit characters.
|
||||
*/
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char ch = (unsigned char) ident[i];
|
||||
unsigned char ch = (unsigned char) ident[i];
|
||||
|
||||
if (ch >= 'A' && ch <= 'Z')
|
||||
ch += 'a' - 'A';
|
||||
@@ -174,12 +175,12 @@ truncate_identifier(char *ident, int len, bool warn)
|
||||
{
|
||||
if (len >= NAMEDATALEN)
|
||||
{
|
||||
len = pg_mbcliplen(ident, len, NAMEDATALEN-1);
|
||||
len = pg_mbcliplen(ident, len, NAMEDATALEN - 1);
|
||||
if (warn)
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_NAME_TOO_LONG),
|
||||
errmsg("identifier \"%s\" will be truncated to \"%.*s\"",
|
||||
ident, len, ident)));
|
||||
errmsg("identifier \"%s\" will be truncated to \"%.*s\"",
|
||||
ident, len, ident)));
|
||||
ident[len] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user