mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Another round of error message editing, covering backend/parser/.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.280 2003/07/18 23:20:32 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.281 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -357,7 +357,9 @@ transformStmt(ParseState *pstate, Node *parseTree,
|
||||
}
|
||||
|
||||
if (aliaslist != NIL)
|
||||
elog(ERROR, "CREATE VIEW specifies more column names than columns");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("CREATE VIEW specifies more column names than columns")));
|
||||
}
|
||||
result = makeNode(Query);
|
||||
result->commandType = CMD_UTILITY;
|
||||
@@ -565,7 +567,9 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
|
||||
Assert(IsA(selectQuery, Query));
|
||||
Assert(selectQuery->commandType == CMD_SELECT);
|
||||
if (selectQuery->into)
|
||||
elog(ERROR, "INSERT ... SELECT may not specify INTO");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("INSERT ... SELECT may not specify INTO")));
|
||||
|
||||
/*
|
||||
* Make the source be a subquery in the INSERT's rangetable, and
|
||||
@@ -655,7 +659,9 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
|
||||
tl = lnext(tl);
|
||||
|
||||
if (icolumns == NIL || attnos == NIL)
|
||||
elog(ERROR, "INSERT has more expressions than target columns");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("INSERT has more expressions than target columns")));
|
||||
|
||||
col = (ResTarget *) lfirst(icolumns);
|
||||
Assert(IsA(col, ResTarget));
|
||||
@@ -675,7 +681,9 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
|
||||
* statements.
|
||||
*/
|
||||
if (stmt->cols != NIL && (icolumns != NIL || attnos != NIL))
|
||||
elog(ERROR, "INSERT has more target columns than expressions");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("INSERT has more target columns than expressions")));
|
||||
|
||||
/* done building the range table and jointree */
|
||||
qry->rtable = pstate->p_rtable;
|
||||
@@ -876,7 +884,9 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt,
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "parser: unrecognized node (internal error)");
|
||||
elog(ERROR, "unrecognized node type: %d",
|
||||
(int) nodeTag(element));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -958,8 +968,10 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
|
||||
sname = makeObjectName(cxt->relation->relname, column->colname, "seq");
|
||||
snamespace = get_namespace_name(RangeVarGetCreationNamespace(cxt->relation));
|
||||
|
||||
elog(NOTICE, "%s will create implicit sequence '%s' for SERIAL column '%s.%s'",
|
||||
cxt->stmtType, sname, cxt->relation->relname, column->colname);
|
||||
ereport(NOTICE,
|
||||
(errmsg("%s will create implicit sequence \"%s\" for SERIAL column \"%s.%s\"",
|
||||
cxt->stmtType, sname,
|
||||
cxt->relation->relname, column->colname)));
|
||||
|
||||
/*
|
||||
* Build a CREATE SEQUENCE command to create the sequence object,
|
||||
@@ -1039,24 +1051,30 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
|
||||
{
|
||||
case CONSTR_NULL:
|
||||
if (saw_nullable && column->is_not_null)
|
||||
elog(ERROR, "%s/(NOT) NULL conflicting declaration for '%s.%s'",
|
||||
cxt->stmtType, cxt->relation->relname, column->colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting NULL/NOT NULL declarations for \"%s.%s\"",
|
||||
cxt->relation->relname, column->colname)));
|
||||
column->is_not_null = FALSE;
|
||||
saw_nullable = true;
|
||||
break;
|
||||
|
||||
case CONSTR_NOTNULL:
|
||||
if (saw_nullable && !column->is_not_null)
|
||||
elog(ERROR, "%s/(NOT) NULL conflicting declaration for '%s.%s'",
|
||||
cxt->stmtType, cxt->relation->relname, column->colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting NULL/NOT NULL declarations for \"%s.%s\"",
|
||||
cxt->relation->relname, column->colname)));
|
||||
column->is_not_null = TRUE;
|
||||
saw_nullable = true;
|
||||
break;
|
||||
|
||||
case CONSTR_DEFAULT:
|
||||
if (column->raw_default != NULL)
|
||||
elog(ERROR, "%s/DEFAULT multiple values specified for '%s.%s'",
|
||||
cxt->stmtType, cxt->relation->relname, column->colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multiple DEFAULT values specified for \"%s.%s\"",
|
||||
cxt->relation->relname, column->colname)));
|
||||
column->raw_default = constraint->raw_expr;
|
||||
Assert(constraint->cooked_expr == NULL);
|
||||
break;
|
||||
@@ -1097,7 +1115,8 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "parser: unrecognized constraint (internal error)");
|
||||
elog(ERROR, "unrecognized constraint type: %d",
|
||||
constraint->contype);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1132,11 +1151,13 @@ transformTableConstraint(ParseState *pstate, CreateStmtContext *cxt,
|
||||
case CONSTR_ATTR_NOT_DEFERRABLE:
|
||||
case CONSTR_ATTR_DEFERRED:
|
||||
case CONSTR_ATTR_IMMEDIATE:
|
||||
elog(ERROR, "parser: illegal context for constraint (internal error)");
|
||||
elog(ERROR, "illegal context for constraint type %d",
|
||||
constraint->contype);
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "parser: unrecognized constraint (internal error)");
|
||||
elog(ERROR, "unrecognized constraint type: %d",
|
||||
constraint->contype);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1161,8 +1182,10 @@ transformInhRelation(ParseState *pstate, CreateStmtContext *cxt,
|
||||
relation = heap_openrv(inhRelation->relation, AccessShareLock);
|
||||
|
||||
if (relation->rd_rel->relkind != RELKIND_RELATION)
|
||||
elog(ERROR, "CREATE TABLE: inherited relation \"%s\" is not a table",
|
||||
inhRelation->relation->relname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("inherited relation \"%s\" is not a table",
|
||||
inhRelation->relation->relname)));
|
||||
|
||||
/*
|
||||
* Check for SELECT privilages
|
||||
@@ -1293,9 +1316,10 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
|
||||
if (cxt->pkey != NULL ||
|
||||
(OidIsValid(cxt->relOid) &&
|
||||
relationHasPrimaryKey(cxt->relOid)))
|
||||
elog(ERROR, "%s / PRIMARY KEY multiple primary keys"
|
||||
" for table '%s' are not allowed",
|
||||
cxt->stmtType, cxt->relation->relname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
|
||||
errmsg("multiple primary keys for table \"%s\" are not allowed",
|
||||
cxt->relation->relname)));
|
||||
cxt->pkey = index;
|
||||
}
|
||||
index->isconstraint = true;
|
||||
@@ -1363,8 +1387,10 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
|
||||
Assert(IsA(inh, RangeVar));
|
||||
rel = heap_openrv(inh, AccessShareLock);
|
||||
if (rel->rd_rel->relkind != RELKIND_RELATION)
|
||||
elog(ERROR, "inherited table \"%s\" is not a relation",
|
||||
inh->relname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("inherited table \"%s\" is not a relation",
|
||||
inh->relname)));
|
||||
for (count = 0; count < rel->rd_att->natts; count++)
|
||||
{
|
||||
Form_pg_attribute inhattr = rel->rd_att->attrs[count];
|
||||
@@ -1407,17 +1433,22 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
|
||||
}
|
||||
|
||||
if (!found)
|
||||
elog(ERROR, "%s: column \"%s\" named in key does not exist",
|
||||
cxt->stmtType, key);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("column \"%s\" named in key does not exist",
|
||||
key)));
|
||||
|
||||
/* Check for PRIMARY KEY(foo, foo) */
|
||||
foreach(columns, index->indexParams)
|
||||
{
|
||||
iparam = (IndexElem *) lfirst(columns);
|
||||
if (iparam->name && strcmp(key, iparam->name) == 0)
|
||||
elog(ERROR, "%s: column \"%s\" appears twice in %s constraint",
|
||||
cxt->stmtType, key,
|
||||
index->primary ? "PRIMARY KEY" : "UNIQUE");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_COLUMN),
|
||||
/* translator: second %s is PRIMARY KEY or UNIQUE */
|
||||
errmsg("column \"%s\" appears twice in %s constraint",
|
||||
key,
|
||||
index->primary ? "PRIMARY KEY" : "UNIQUE")));
|
||||
}
|
||||
|
||||
/* OK, add it to the index definition */
|
||||
@@ -1506,14 +1537,14 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
|
||||
cxt->alist);
|
||||
}
|
||||
if (index->idxname == NULL) /* should not happen */
|
||||
elog(ERROR, "%s: failed to make implicit index name",
|
||||
cxt->stmtType);
|
||||
elog(ERROR, "failed to make implicit index name");
|
||||
|
||||
elog(NOTICE, "%s / %s%s will create implicit index '%s' for table '%s'",
|
||||
cxt->stmtType,
|
||||
(strcmp(cxt->stmtType, "ALTER TABLE") == 0) ? "ADD " : "",
|
||||
(index->primary ? "PRIMARY KEY" : "UNIQUE"),
|
||||
index->idxname, cxt->relation->relname);
|
||||
ereport(NOTICE,
|
||||
(errmsg("%s / %s%s will create implicit index \"%s\" for table \"%s\"",
|
||||
cxt->stmtType,
|
||||
(strcmp(cxt->stmtType, "ALTER TABLE") == 0) ? "ADD " : "",
|
||||
(index->primary ? "PRIMARY KEY" : "UNIQUE"),
|
||||
index->idxname, cxt->relation->relname)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1524,8 +1555,9 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt,
|
||||
if (cxt->fkconstraints == NIL)
|
||||
return;
|
||||
|
||||
elog(NOTICE, "%s will create implicit trigger(s) for FOREIGN KEY check(s)",
|
||||
cxt->stmtType);
|
||||
ereport(NOTICE,
|
||||
(errmsg("%s will create implicit trigger(s) for FOREIGN KEY check(s)",
|
||||
cxt->stmtType)));
|
||||
|
||||
/*
|
||||
* For ALTER TABLE ADD CONSTRAINT, nothing to do. For CREATE TABLE or
|
||||
@@ -1614,7 +1646,9 @@ transformIndexStmt(ParseState *pstate, IndexStmt *stmt)
|
||||
* the predicate. DefineIndex() will make more checks.
|
||||
*/
|
||||
if (expression_returns_set(ielem->expr))
|
||||
elog(ERROR, "index expression may not return a set");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("index expression may not return a set")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1694,7 +1728,7 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
|
||||
addRTEtoQuery(pstate, oldrte, false, true);
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "transformRuleStmt: unexpected event type %d",
|
||||
elog(ERROR, "unrecognized event type: %d",
|
||||
(int) stmt->event);
|
||||
break;
|
||||
}
|
||||
@@ -1704,11 +1738,15 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
|
||||
"WHERE");
|
||||
|
||||
if (length(pstate->p_rtable) != 2) /* naughty, naughty... */
|
||||
elog(ERROR, "Rule WHERE condition may not contain references to other relations");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("rule WHERE condition may not contain references to other relations")));
|
||||
|
||||
/* aggregates not allowed (but subselects are okay) */
|
||||
if (pstate->p_hasAggs)
|
||||
elog(ERROR, "Rule WHERE condition may not contain aggregate functions");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("rule WHERE condition may not contain aggregate functions")));
|
||||
|
||||
/* save info about sublinks in where clause */
|
||||
qry->hasSubLinks = pstate->p_hasSubLinks;
|
||||
@@ -1777,7 +1815,9 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
|
||||
*/
|
||||
if (top_subqry->commandType == CMD_UTILITY &&
|
||||
stmt->whereClause != NULL)
|
||||
elog(ERROR, "Rules with WHERE conditions may only have SELECT, INSERT, UPDATE, or DELETE actions");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("rules with WHERE conditions may only have SELECT, INSERT, UPDATE, or DELETE actions")));
|
||||
|
||||
/*
|
||||
* If the action is INSERT...SELECT, OLD/NEW have been pushed
|
||||
@@ -1794,7 +1834,9 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
|
||||
* such a rule immediately.
|
||||
*/
|
||||
if (sub_qry->setOperations != NULL && stmt->whereClause != NULL)
|
||||
elog(ERROR, "Conditional UNION/INTERSECT/EXCEPT statements are not implemented");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
|
||||
|
||||
/*
|
||||
* Validate action's use of OLD/NEW, qual too
|
||||
@@ -1810,23 +1852,31 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
|
||||
{
|
||||
case CMD_SELECT:
|
||||
if (has_old)
|
||||
elog(ERROR, "ON SELECT rule may not use OLD");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("ON SELECT rule may not use OLD")));
|
||||
if (has_new)
|
||||
elog(ERROR, "ON SELECT rule may not use NEW");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("ON SELECT rule may not use NEW")));
|
||||
break;
|
||||
case CMD_UPDATE:
|
||||
/* both are OK */
|
||||
break;
|
||||
case CMD_INSERT:
|
||||
if (has_old)
|
||||
elog(ERROR, "ON INSERT rule may not use OLD");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("ON INSERT rule may not use OLD")));
|
||||
break;
|
||||
case CMD_DELETE:
|
||||
if (has_new)
|
||||
elog(ERROR, "ON DELETE rule may not use NEW");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("ON DELETE rule may not use NEW")));
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "transformRuleStmt: unexpected event type %d",
|
||||
elog(ERROR, "unrecognized event type: %d",
|
||||
(int) stmt->event);
|
||||
break;
|
||||
}
|
||||
@@ -1856,7 +1906,9 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
|
||||
* should be a can't-happen case because of prior tests.)
|
||||
*/
|
||||
if (sub_qry->setOperations != NULL)
|
||||
elog(ERROR, "Conditional UNION/INTERSECT/EXCEPT statements are not implemented");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
|
||||
/* hack so we can use addRTEtoQuery() */
|
||||
sub_pstate->p_rtable = sub_qry->rtable;
|
||||
sub_pstate->p_joinlist = sub_qry->jointree->fromlist;
|
||||
@@ -2026,7 +2078,9 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
|
||||
|
||||
/* We don't support forUpdate with set ops at the moment. */
|
||||
if (forUpdate)
|
||||
elog(ERROR, "SELECT FOR UPDATE is not allowed with UNION/INTERSECT/EXCEPT");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE is not allowed with UNION/INTERSECT/EXCEPT")));
|
||||
|
||||
/*
|
||||
* Recursively transform the components of the tree.
|
||||
@@ -2143,7 +2197,9 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
|
||||
pstate->p_rtable = sv_rtable;
|
||||
|
||||
if (tllen != length(qry->targetList))
|
||||
elog(ERROR, "ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of the result columns");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of the result columns")));
|
||||
|
||||
qry->limitOffset = transformLimitClause(pstate, limitOffset,
|
||||
"OFFSET");
|
||||
@@ -2179,10 +2235,14 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt)
|
||||
* Validity-check both leaf and internal SELECTs for disallowed ops.
|
||||
*/
|
||||
if (stmt->into)
|
||||
elog(ERROR, "INTO is only allowed on first SELECT of UNION/INTERSECT/EXCEPT");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("INTO is only allowed on first SELECT of UNION/INTERSECT/EXCEPT")));
|
||||
/* We don't support forUpdate with set ops at the moment. */
|
||||
if (stmt->forUpdate)
|
||||
elog(ERROR, "SELECT FOR UPDATE is not allowed with UNION/INTERSECT/EXCEPT");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE is not allowed with UNION/INTERSECT/EXCEPT")));
|
||||
|
||||
/*
|
||||
* If an internal node of a set-op tree has ORDER BY, UPDATE, or LIMIT
|
||||
@@ -2236,13 +2296,16 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt)
|
||||
if (pstate->p_namespace)
|
||||
{
|
||||
if (contain_vars_of_level((Node *) selectQuery, 1))
|
||||
elog(ERROR, "UNION/INTERSECT/EXCEPT member statement may not refer to other relations of same query level");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("UNION/INTERSECT/EXCEPT member statement may not refer to other relations of same query level")));
|
||||
}
|
||||
|
||||
/*
|
||||
* Make the leaf query be a subquery in the top-level rangetable.
|
||||
*/
|
||||
snprintf(selectName, sizeof(selectName), "*SELECT* %d", length(pstate->p_rtable) + 1);
|
||||
snprintf(selectName, sizeof(selectName), "*SELECT* %d",
|
||||
length(pstate->p_rtable) + 1);
|
||||
rte = addRangeTableEntryForSubquery(pstate,
|
||||
selectQuery,
|
||||
makeAlias(selectName, NIL),
|
||||
@@ -2286,8 +2349,10 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt)
|
||||
lcoltypes = getSetColTypes(pstate, op->larg);
|
||||
rcoltypes = getSetColTypes(pstate, op->rarg);
|
||||
if (length(lcoltypes) != length(rcoltypes))
|
||||
elog(ERROR, "Each %s query must have the same number of columns",
|
||||
context);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("each %s query must have the same number of columns",
|
||||
context)));
|
||||
op->colTypes = NIL;
|
||||
while (lcoltypes != NIL)
|
||||
{
|
||||
@@ -2344,8 +2409,7 @@ getSetColTypes(ParseState *pstate, Node *node)
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(ERROR, "getSetColTypes: unexpected node %d",
|
||||
(int) nodeTag(node));
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
|
||||
return NIL; /* keep compiler quiet */
|
||||
}
|
||||
}
|
||||
@@ -2355,7 +2419,9 @@ static void
|
||||
applyColumnNames(List *dst, List *src)
|
||||
{
|
||||
if (length(src) > length(dst))
|
||||
elog(ERROR, "CREATE TABLE AS specifies too many column names");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("CREATE TABLE AS specifies too many column names")));
|
||||
|
||||
while (src != NIL && dst != NIL)
|
||||
{
|
||||
@@ -2535,7 +2601,8 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
|
||||
else if (IsA(stmt->def, FkConstraint))
|
||||
cxt.fkconstraints = lappend(cxt.fkconstraints, stmt->def);
|
||||
else
|
||||
elog(ERROR, "Unexpected node type in ALTER TABLE ADD CONSTRAINT");
|
||||
elog(ERROR, "unrecognized node type: %d",
|
||||
(int) nodeTag(stmt->def));
|
||||
|
||||
transformIndexConstraints(pstate, &cxt);
|
||||
transformFKConstraints(pstate, &cxt, true);
|
||||
@@ -2584,14 +2651,16 @@ transformDeclareCursorStmt(ParseState *pstate, DeclareCursorStmt *stmt)
|
||||
*/
|
||||
if ((stmt->options & CURSOR_OPT_SCROLL) &&
|
||||
(stmt->options & CURSOR_OPT_NO_SCROLL))
|
||||
elog(ERROR, "Cannot specify both SCROLL and NO SCROLL");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_CURSOR_DEFINITION),
|
||||
errmsg("cannot specify both SCROLL and NO SCROLL")));
|
||||
|
||||
stmt->query = (Node *) transformStmt(pstate, stmt->query,
|
||||
&extras_before, &extras_after);
|
||||
|
||||
/* Shouldn't get any extras, since grammar only allows SelectStmt */
|
||||
if (extras_before || extras_after)
|
||||
elog(ERROR, "transformDeclareCursorStmt: internal error");
|
||||
elog(ERROR, "unexpected extra stuff in cursor statement");
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -2642,7 +2711,7 @@ transformPrepareStmt(ParseState *pstate, PrepareStmt *stmt)
|
||||
* OptimizableStmt
|
||||
*/
|
||||
if (length(queries) != 1)
|
||||
elog(ERROR, "transformPrepareStmt: internal error");
|
||||
elog(ERROR, "unexpected extra stuff in prepared statement");
|
||||
|
||||
stmt->query = lfirst(queries);
|
||||
|
||||
@@ -2668,8 +2737,12 @@ transformExecuteStmt(ParseState *pstate, ExecuteStmt *stmt)
|
||||
int i = 1;
|
||||
|
||||
if (nparams != nexpected)
|
||||
elog(ERROR, "Wrong number of parameters, expected %d but got %d",
|
||||
nexpected, nparams);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("wrong number of parameters for prepared statement \"%s\"",
|
||||
stmt->name),
|
||||
errdetail("Expected %d parameters but got %d.",
|
||||
nexpected, nparams)));
|
||||
|
||||
foreach(l, stmt->params)
|
||||
{
|
||||
@@ -2681,9 +2754,13 @@ transformExecuteStmt(ParseState *pstate, ExecuteStmt *stmt)
|
||||
|
||||
/* Cannot contain subselects or aggregates */
|
||||
if (pstate->p_hasSubLinks)
|
||||
elog(ERROR, "Cannot use subselects in EXECUTE parameters");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot use sub-selects in EXECUTE parameters")));
|
||||
if (pstate->p_hasAggs)
|
||||
elog(ERROR, "Cannot use aggregates in EXECUTE parameters");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("cannot use aggregates in EXECUTE parameters")));
|
||||
|
||||
given_type_id = exprType(expr);
|
||||
expected_type_id = lfirsto(paramtypes);
|
||||
@@ -2694,11 +2771,13 @@ transformExecuteStmt(ParseState *pstate, ExecuteStmt *stmt)
|
||||
COERCE_IMPLICIT_CAST);
|
||||
|
||||
if (expr == NULL)
|
||||
elog(ERROR, "Parameter $%d of type %s cannot be coerced into the expected type %s"
|
||||
"\n\tYou will need to rewrite or cast the expression",
|
||||
i,
|
||||
format_type_be(given_type_id),
|
||||
format_type_be(expected_type_id));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("parameter $%d of type %s cannot be coerced to the expected type %s",
|
||||
i,
|
||||
format_type_be(given_type_id),
|
||||
format_type_be(expected_type_id)),
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
|
||||
lfirst(l) = expr;
|
||||
|
||||
@@ -2715,13 +2794,21 @@ void
|
||||
CheckSelectForUpdate(Query *qry)
|
||||
{
|
||||
if (qry->setOperations)
|
||||
elog(ERROR, "SELECT FOR UPDATE is not allowed with UNION/INTERSECT/EXCEPT");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE is not allowed with UNION/INTERSECT/EXCEPT")));
|
||||
if (qry->distinctClause != NIL)
|
||||
elog(ERROR, "SELECT FOR UPDATE is not allowed with DISTINCT clause");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE is not allowed with DISTINCT clause")));
|
||||
if (qry->groupClause != NIL)
|
||||
elog(ERROR, "SELECT FOR UPDATE is not allowed with GROUP BY clause");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE is not allowed with GROUP BY clause")));
|
||||
if (qry->hasAggs)
|
||||
elog(ERROR, "SELECT FOR UPDATE is not allowed with AGGREGATE");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE is not allowed with AGGREGATE")));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2786,8 +2873,10 @@ transformForUpdate(Query *qry, List *forUpdate)
|
||||
}
|
||||
}
|
||||
if (rt == NIL)
|
||||
elog(ERROR, "FOR UPDATE: relation \"%s\" not found in FROM clause",
|
||||
relname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_TABLE),
|
||||
errmsg("relation \"%s\" in FOR UPDATE clause not found in FROM clause",
|
||||
relname)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2825,9 +2914,8 @@ relationHasPrimaryKey(Oid relationOid)
|
||||
indexTuple = SearchSysCache(INDEXRELID,
|
||||
ObjectIdGetDatum(indexoid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(indexTuple))
|
||||
elog(ERROR, "relationHasPrimaryKey: index %u not found",
|
||||
indexoid);
|
||||
if (!HeapTupleIsValid(indexTuple)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for index %u", indexoid);
|
||||
result = ((Form_pg_index) GETSTRUCT(indexTuple))->indisprimary;
|
||||
ReleaseSysCache(indexTuple);
|
||||
if (result)
|
||||
@@ -2877,30 +2965,44 @@ transformConstraintAttrs(List *constraintList)
|
||||
case CONSTR_ATTR_DEFERRABLE:
|
||||
if (lastprimarynode == NULL ||
|
||||
!IsA(lastprimarynode, FkConstraint))
|
||||
elog(ERROR, "Misplaced DEFERRABLE clause");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("misplaced DEFERRABLE clause")));
|
||||
if (saw_deferrability)
|
||||
elog(ERROR, "Multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed")));
|
||||
saw_deferrability = true;
|
||||
((FkConstraint *) lastprimarynode)->deferrable = true;
|
||||
break;
|
||||
case CONSTR_ATTR_NOT_DEFERRABLE:
|
||||
if (lastprimarynode == NULL ||
|
||||
!IsA(lastprimarynode, FkConstraint))
|
||||
elog(ERROR, "Misplaced NOT DEFERRABLE clause");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("misplaced NOT DEFERRABLE clause")));
|
||||
if (saw_deferrability)
|
||||
elog(ERROR, "Multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed")));
|
||||
saw_deferrability = true;
|
||||
((FkConstraint *) lastprimarynode)->deferrable = false;
|
||||
if (saw_initially &&
|
||||
((FkConstraint *) lastprimarynode)->initdeferred)
|
||||
elog(ERROR, "INITIALLY DEFERRED constraint must be DEFERRABLE");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("INITIALLY DEFERRED constraint must be DEFERRABLE")));
|
||||
break;
|
||||
case CONSTR_ATTR_DEFERRED:
|
||||
if (lastprimarynode == NULL ||
|
||||
!IsA(lastprimarynode, FkConstraint))
|
||||
elog(ERROR, "Misplaced INITIALLY DEFERRED clause");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("misplaced INITIALLY DEFERRED clause")));
|
||||
if (saw_initially)
|
||||
elog(ERROR, "Multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed")));
|
||||
saw_initially = true;
|
||||
((FkConstraint *) lastprimarynode)->initdeferred = true;
|
||||
|
||||
@@ -2911,14 +3013,20 @@ transformConstraintAttrs(List *constraintList)
|
||||
if (!saw_deferrability)
|
||||
((FkConstraint *) lastprimarynode)->deferrable = true;
|
||||
else if (!((FkConstraint *) lastprimarynode)->deferrable)
|
||||
elog(ERROR, "INITIALLY DEFERRED constraint must be DEFERRABLE");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("INITIALLY DEFERRED constraint must be DEFERRABLE")));
|
||||
break;
|
||||
case CONSTR_ATTR_IMMEDIATE:
|
||||
if (lastprimarynode == NULL ||
|
||||
!IsA(lastprimarynode, FkConstraint))
|
||||
elog(ERROR, "Misplaced INITIALLY IMMEDIATE clause");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("misplaced INITIALLY IMMEDIATE clause")));
|
||||
if (saw_initially)
|
||||
elog(ERROR, "Multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed")));
|
||||
saw_initially = true;
|
||||
((FkConstraint *) lastprimarynode)->initdeferred = false;
|
||||
break;
|
||||
@@ -3025,9 +3133,11 @@ analyzeCreateSchemaStmt(CreateSchemaStmt *stmt)
|
||||
if (elp->relation->schemaname == NULL)
|
||||
elp->relation->schemaname = cxt.schemaname;
|
||||
else if (strcmp(cxt.schemaname, elp->relation->schemaname) != 0)
|
||||
elog(ERROR, "New table specifies a schema (%s)"
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_SCHEMA_DEFINITION),
|
||||
errmsg("CREATE specifies a schema (%s)"
|
||||
" different from the one being created (%s)",
|
||||
elp->relation->schemaname, cxt.schemaname);
|
||||
elp->relation->schemaname, cxt.schemaname)));
|
||||
|
||||
/*
|
||||
* XXX todo: deal with constraints
|
||||
@@ -3044,9 +3154,11 @@ analyzeCreateSchemaStmt(CreateSchemaStmt *stmt)
|
||||
if (elp->view->schemaname == NULL)
|
||||
elp->view->schemaname = cxt.schemaname;
|
||||
else if (strcmp(cxt.schemaname, elp->view->schemaname) != 0)
|
||||
elog(ERROR, "New view specifies a schema (%s)"
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_SCHEMA_DEFINITION),
|
||||
errmsg("CREATE specifies a schema (%s)"
|
||||
" different from the one being created (%s)",
|
||||
elp->view->schemaname, cxt.schemaname);
|
||||
elp->view->schemaname, cxt.schemaname)));
|
||||
|
||||
/*
|
||||
* XXX todo: deal with references between views
|
||||
@@ -3061,7 +3173,8 @@ analyzeCreateSchemaStmt(CreateSchemaStmt *stmt)
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "parser: unsupported schema node (internal error)");
|
||||
elog(ERROR, "unrecognized node type: %d",
|
||||
(int) nodeTag(element));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.426 2003/07/03 19:07:36 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.427 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@@ -956,9 +956,9 @@ zone_value:
|
||||
if ($3 != INTERVAL_FULL_RANGE)
|
||||
{
|
||||
if (($3 & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
|
||||
elog(ERROR,
|
||||
"Time zone interval"
|
||||
" must be HOUR or HOUR TO MINUTE");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("time zone interval must be HOUR or HOUR TO MINUTE")));
|
||||
n->typename->typmod = INTERVAL_TYPMOD(INTERVAL_FULL_PRECISION, $3);
|
||||
}
|
||||
$$ = (Node *)n;
|
||||
@@ -967,22 +967,24 @@ zone_value:
|
||||
{
|
||||
A_Const *n = (A_Const *) makeStringConst($5, $1);
|
||||
if ($3 < 0)
|
||||
elog(ERROR,
|
||||
"INTERVAL(%d) precision must not be negative",
|
||||
$3);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("INTERVAL(%d) precision must not be negative",
|
||||
$3)));
|
||||
if ($3 > MAX_INTERVAL_PRECISION)
|
||||
{
|
||||
elog(NOTICE,
|
||||
"INTERVAL(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_INTERVAL_PRECISION);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_INTERVAL_PRECISION)));
|
||||
$3 = MAX_INTERVAL_PRECISION;
|
||||
}
|
||||
|
||||
if (($6 != INTERVAL_FULL_RANGE)
|
||||
&& (($6 & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0))
|
||||
elog(ERROR,
|
||||
"Time zone interval"
|
||||
" must be HOUR or HOUR TO MINUTE");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("time zone interval must be HOUR or HOUR TO MINUTE")));
|
||||
|
||||
n->typename->typmod = INTERVAL_TYPMOD($3, $6);
|
||||
|
||||
@@ -1467,9 +1469,9 @@ columnDef: ColId Typename ColQualList opt_collate
|
||||
n->is_local = true;
|
||||
|
||||
if ($4 != NULL)
|
||||
elog(NOTICE,
|
||||
"CREATE TABLE / COLLATE %s not yet implemented; "
|
||||
"clause ignored", $4);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("CREATE TABLE / COLLATE is not yet implemented; clause ignored")));
|
||||
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
@@ -1769,7 +1771,9 @@ key_match: MATCH FULL
|
||||
}
|
||||
| MATCH PARTIAL
|
||||
{
|
||||
elog(ERROR, "FOREIGN KEY/MATCH PARTIAL not yet implemented");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("FOREIGN KEY/MATCH PARTIAL is not yet implemented")));
|
||||
$$ = FKCONSTR_MATCH_PARTIAL;
|
||||
}
|
||||
| MATCH SIMPLE
|
||||
@@ -1849,7 +1853,9 @@ CreateAsStmt:
|
||||
*/
|
||||
SelectStmt *n = findLeftmostSelect((SelectStmt *) $7);
|
||||
if (n->into != NULL)
|
||||
elog(ERROR, "CREATE TABLE AS may not specify INTO");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("CREATE TABLE AS may not specify INTO")));
|
||||
$4->istemp = $2;
|
||||
n->into = $4;
|
||||
n->intoColNames = $5;
|
||||
@@ -2188,8 +2194,9 @@ ConstraintAttributeSpec:
|
||||
| ConstraintDeferrabilitySpec ConstraintTimeSpec
|
||||
{
|
||||
if ($1 == 0 && $2 != 0)
|
||||
elog(ERROR,
|
||||
"INITIALLY DEFERRED constraint must be DEFERRABLE");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("INITIALLY DEFERRED constraint must be DEFERRABLE")));
|
||||
$$ = $1 | $2;
|
||||
}
|
||||
| ConstraintTimeSpec
|
||||
@@ -2202,8 +2209,9 @@ ConstraintAttributeSpec:
|
||||
| ConstraintTimeSpec ConstraintDeferrabilitySpec
|
||||
{
|
||||
if ($2 == 0 && $1 != 0)
|
||||
elog(ERROR,
|
||||
"INITIALLY DEFERRED constraint must be DEFERRABLE");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("INITIALLY DEFERRED constraint must be DEFERRABLE")));
|
||||
$$ = $1 | $2;
|
||||
}
|
||||
| /*EMPTY*/
|
||||
@@ -2253,7 +2261,9 @@ CreateAssertStmt:
|
||||
n->deferrable = ($8 & 1) != 0;
|
||||
n->initdeferred = ($8 & 2) != 0;
|
||||
|
||||
elog(ERROR, "CREATE ASSERTION is not yet supported");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("CREATE ASSERTION is not yet implemented")));
|
||||
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
@@ -2267,7 +2277,9 @@ DropAssertStmt:
|
||||
n->property = $3;
|
||||
n->behavior = $4;
|
||||
n->removeType = OBJECT_TRIGGER; /* XXX */
|
||||
elog(ERROR, "DROP ASSERTION is not yet supported");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("DROP ASSERTION is not yet implemented")));
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
;
|
||||
@@ -2329,9 +2341,10 @@ DefineStmt:
|
||||
r->relname = strVal(lthird($3));
|
||||
break;
|
||||
default:
|
||||
elog(ERROR,
|
||||
"Improper qualified name (too many dotted names): %s",
|
||||
NameListToString($3));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("improper qualified name (too many dotted names): %s",
|
||||
NameListToString($3))));
|
||||
break;
|
||||
}
|
||||
n->typevar = r;
|
||||
@@ -3074,14 +3087,16 @@ func_arg: opt_arg func_type
|
||||
opt_arg: IN_P { $$ = FALSE; }
|
||||
| OUT_P
|
||||
{
|
||||
elog(ERROR,
|
||||
"CREATE FUNCTION / OUT parameters are not supported");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("CREATE FUNCTION / OUT parameters are not implemented")));
|
||||
$$ = TRUE;
|
||||
}
|
||||
| INOUT
|
||||
{
|
||||
elog(ERROR,
|
||||
"CREATE FUNCTION / INOUT parameters are not supported");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("CREATE FUNCTION / INOUT parameters are not implemented")));
|
||||
$$ = FALSE;
|
||||
}
|
||||
;
|
||||
@@ -3233,7 +3248,9 @@ RemoveOperStmt:
|
||||
oper_argtypes:
|
||||
Typename
|
||||
{
|
||||
elog(ERROR, "parser: argument type missing (use NONE for unary operators)");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("argument type missing (use NONE for unary operators)")));
|
||||
}
|
||||
| Typename ',' Typename
|
||||
{ $$ = makeList2($1, $3); }
|
||||
@@ -3833,8 +3850,9 @@ CreateDomainStmt:
|
||||
n->constraints = $6;
|
||||
|
||||
if ($7 != NULL)
|
||||
elog(NOTICE,"CREATE DOMAIN / COLLATE %s not yet "
|
||||
"implemented; clause ignored", $7);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("CREATE DOMAIN / COLLATE is not yet implemented; clause ignored")));
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
;
|
||||
@@ -4137,7 +4155,9 @@ ExecuteStmt: EXECUTE name execute_param_clause
|
||||
$4->istemp = $2;
|
||||
n->into = $4;
|
||||
if ($5)
|
||||
elog(ERROR, "column name list not allowed in CREATE TABLE / AS EXECUTE");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
|
||||
/* ... because it's not implemented, but it could be */
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
@@ -4587,8 +4607,10 @@ select_limit:
|
||||
| LIMIT select_limit_value ',' select_offset_value
|
||||
{
|
||||
/* Disabled because it was too confusing, bjm 2002-02-18 */
|
||||
elog(ERROR,
|
||||
"LIMIT #,# syntax not supported.\n\tUse separate LIMIT and OFFSET clauses.");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("LIMIT #,# syntax is not supported"),
|
||||
errhint("Use separate LIMIT and OFFSET clauses.")));
|
||||
}
|
||||
;
|
||||
|
||||
@@ -4735,8 +4757,10 @@ table_ref: relation_expr
|
||||
* However, it does seem like a good idea to emit
|
||||
* an error message that's better than "syntax error".
|
||||
*/
|
||||
elog(ERROR, "sub-SELECT in FROM must have an alias"
|
||||
"\n\tFor example, FROM (SELECT ...) [AS] foo");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("sub-select in FROM must have an alias"),
|
||||
errhint("For example, FROM (SELECT ...) [AS] foo.")));
|
||||
$$ = NULL;
|
||||
}
|
||||
| select_with_parens alias_clause
|
||||
@@ -5058,14 +5082,16 @@ SimpleTypename:
|
||||
{
|
||||
$$ = $1;
|
||||
if ($3 < 0)
|
||||
elog(ERROR,
|
||||
"INTERVAL(%d) precision must not be negative",
|
||||
$3);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("INTERVAL(%d) precision must not be negative",
|
||||
$3)));
|
||||
if ($3 > MAX_INTERVAL_PRECISION)
|
||||
{
|
||||
elog(NOTICE,
|
||||
"INTERVAL(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_INTERVAL_PRECISION);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_INTERVAL_PRECISION)));
|
||||
$3 = MAX_INTERVAL_PRECISION;
|
||||
}
|
||||
$$->typmod = INTERVAL_TYPMOD($3, $5);
|
||||
@@ -5159,15 +5185,17 @@ Numeric: INT_P
|
||||
opt_float: '(' Iconst ')'
|
||||
{
|
||||
if ($2 < 1)
|
||||
elog(ERROR,
|
||||
"precision for FLOAT must be at least 1 bit");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("precision for FLOAT must be at least 1 bit")));
|
||||
else if ($2 <= 24)
|
||||
$$ = SystemTypeName("float4");
|
||||
else if ($2 <= 53)
|
||||
$$ = SystemTypeName("float8");
|
||||
else
|
||||
elog(ERROR,
|
||||
"precision for FLOAT must be less than 54 bits");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("precision for FLOAT must be less than 54 bits")));
|
||||
}
|
||||
| /*EMPTY*/
|
||||
{
|
||||
@@ -5179,22 +5207,25 @@ opt_numeric:
|
||||
'(' Iconst ',' Iconst ')'
|
||||
{
|
||||
if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
|
||||
elog(ERROR,
|
||||
"NUMERIC precision %d must be between 1 and %d",
|
||||
$2, NUMERIC_MAX_PRECISION);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("NUMERIC precision %d must be between 1 and %d",
|
||||
$2, NUMERIC_MAX_PRECISION)));
|
||||
if ($4 < 0 || $4 > $2)
|
||||
elog(ERROR,
|
||||
"NUMERIC scale %d must be between 0 and precision %d",
|
||||
$4,$2);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("NUMERIC scale %d must be between 0 and precision %d",
|
||||
$4, $2)));
|
||||
|
||||
$$ = (($2 << 16) | $4) + VARHDRSZ;
|
||||
}
|
||||
| '(' Iconst ')'
|
||||
{
|
||||
if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
|
||||
elog(ERROR,
|
||||
"NUMERIC precision %d must be between 1 and %d",
|
||||
$2, NUMERIC_MAX_PRECISION);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("NUMERIC precision %d must be between 1 and %d",
|
||||
$2, NUMERIC_MAX_PRECISION)));
|
||||
|
||||
$$ = ($2 << 16) + VARHDRSZ;
|
||||
}
|
||||
@@ -5209,22 +5240,25 @@ opt_decimal:
|
||||
'(' Iconst ',' Iconst ')'
|
||||
{
|
||||
if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
|
||||
elog(ERROR,
|
||||
"DECIMAL precision %d must be between 1 and %d",
|
||||
$2, NUMERIC_MAX_PRECISION);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("DECIMAL precision %d must be between 1 and %d",
|
||||
$2, NUMERIC_MAX_PRECISION)));
|
||||
if ($4 < 0 || $4 > $2)
|
||||
elog(ERROR,
|
||||
"DECIMAL scale %d must be between 0 and precision %d",
|
||||
$4,$2);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("DECIMAL scale %d must be between 0 and precision %d",
|
||||
$4, $2)));
|
||||
|
||||
$$ = (($2 << 16) | $4) + VARHDRSZ;
|
||||
}
|
||||
| '(' Iconst ')'
|
||||
{
|
||||
if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
|
||||
elog(ERROR,
|
||||
"DECIMAL precision %d must be between 1 and %d",
|
||||
$2, NUMERIC_MAX_PRECISION);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("DECIMAL precision %d must be between 1 and %d",
|
||||
$2, NUMERIC_MAX_PRECISION)));
|
||||
|
||||
$$ = ($2 << 16) + VARHDRSZ;
|
||||
}
|
||||
@@ -5271,11 +5305,15 @@ BitWithLength:
|
||||
typname = $2 ? "varbit" : "bit";
|
||||
$$ = SystemTypeName(typname);
|
||||
if ($4 < 1)
|
||||
elog(ERROR, "length for type '%s' must be at least 1",
|
||||
typname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("length for type %s must be at least 1",
|
||||
typname)));
|
||||
else if ($4 > (MaxAttrSize * BITS_PER_BYTE))
|
||||
elog(ERROR, "length for type '%s' cannot exceed %d",
|
||||
typname, (MaxAttrSize * BITS_PER_BYTE));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("length for type %s cannot exceed %d",
|
||||
typname, MaxAttrSize * BITS_PER_BYTE)));
|
||||
$$->typmod = $4;
|
||||
}
|
||||
;
|
||||
@@ -5345,11 +5383,15 @@ CharacterWithLength: character '(' Iconst ')' opt_charset
|
||||
$$ = SystemTypeName($1);
|
||||
|
||||
if ($3 < 1)
|
||||
elog(ERROR, "length for type '%s' must be at least 1",
|
||||
$1);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("length for type %s must be at least 1",
|
||||
$1)));
|
||||
else if ($3 > MaxAttrSize)
|
||||
elog(ERROR, "length for type '%s' cannot exceed %d",
|
||||
$1, MaxAttrSize);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("length for type %s cannot exceed %d",
|
||||
$1, MaxAttrSize)));
|
||||
|
||||
/* we actually implement these like a varlen, so
|
||||
* the first 4 bytes is the length. (the difference
|
||||
@@ -5424,15 +5466,17 @@ ConstDatetime:
|
||||
*/
|
||||
$$->timezone = $5;
|
||||
if ($3 < 0)
|
||||
elog(ERROR,
|
||||
"TIMESTAMP(%d)%s precision must not be negative",
|
||||
$3, ($5 ? " WITH TIME ZONE": ""));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("TIMESTAMP(%d)%s precision must not be negative",
|
||||
$3, ($5 ? " WITH TIME ZONE": ""))));
|
||||
if ($3 > MAX_TIMESTAMP_PRECISION)
|
||||
{
|
||||
elog(NOTICE,
|
||||
"TIMESTAMP(%d)%s precision reduced to maximum allowed, %d",
|
||||
$3, ($5 ? " WITH TIME ZONE": ""),
|
||||
MAX_TIMESTAMP_PRECISION);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("TIMESTAMP(%d)%s precision reduced to maximum allowed, %d",
|
||||
$3, ($5 ? " WITH TIME ZONE": ""),
|
||||
MAX_TIMESTAMP_PRECISION)));
|
||||
$3 = MAX_TIMESTAMP_PRECISION;
|
||||
}
|
||||
$$->typmod = $3;
|
||||
@@ -5463,15 +5507,17 @@ ConstDatetime:
|
||||
else
|
||||
$$ = SystemTypeName("time");
|
||||
if ($3 < 0)
|
||||
elog(ERROR,
|
||||
"TIME(%d)%s precision must not be negative",
|
||||
$3, ($5 ? " WITH TIME ZONE": ""));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("TIME(%d)%s precision must not be negative",
|
||||
$3, ($5 ? " WITH TIME ZONE": ""))));
|
||||
if ($3 > MAX_TIME_PRECISION)
|
||||
{
|
||||
elog(NOTICE,
|
||||
"TIME(%d)%s precision reduced to maximum allowed, %d",
|
||||
$3, ($5 ? " WITH TIME ZONE": ""),
|
||||
MAX_TIME_PRECISION);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("TIME(%d)%s precision reduced to maximum allowed, %d",
|
||||
$3, ($5 ? " WITH TIME ZONE": ""),
|
||||
MAX_TIME_PRECISION)));
|
||||
$3 = MAX_TIME_PRECISION;
|
||||
}
|
||||
$$->typmod = $3;
|
||||
@@ -5613,7 +5659,9 @@ r_expr: row IN_P select_with_parens
|
||||
/* lengths don't match? then complain */
|
||||
if (length(largs) != length(rargs))
|
||||
{
|
||||
elog(ERROR, "Unequal number of entries in row expression");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("unequal number of entries in row expression")));
|
||||
}
|
||||
/* both are zero-length rows? then they are not distinct */
|
||||
else if (length(largs) <= 0)
|
||||
@@ -6033,7 +6081,9 @@ a_expr: c_expr { $$ = $1; }
|
||||
* entire result equal to one.
|
||||
* But, will probably implement a separate node in the executor.
|
||||
*/
|
||||
elog(ERROR, "UNIQUE predicate is not yet implemented");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("UNIQUE predicate is not yet implemented")));
|
||||
}
|
||||
| r_expr
|
||||
{ $$ = $1; }
|
||||
@@ -6273,14 +6323,16 @@ c_expr: columnref { $$ = (Node *) $1; }
|
||||
s->typename = SystemTypeName("text");
|
||||
d = SystemTypeName("timetz");
|
||||
if ($3 < 0)
|
||||
elog(ERROR,
|
||||
"CURRENT_TIME(%d) precision must not be negative",
|
||||
$3);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("CURRENT_TIME(%d) precision must not be negative",
|
||||
$3)));
|
||||
if ($3 > MAX_TIME_PRECISION)
|
||||
{
|
||||
elog(NOTICE,
|
||||
"CURRENT_TIME(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_TIME_PRECISION);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("CURRENT_TIME(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_TIME_PRECISION)));
|
||||
$3 = MAX_TIME_PRECISION;
|
||||
}
|
||||
d->typmod = $3;
|
||||
@@ -6325,14 +6377,16 @@ c_expr: columnref { $$ = (Node *) $1; }
|
||||
|
||||
d = SystemTypeName("timestamptz");
|
||||
if ($3 < 0)
|
||||
elog(ERROR,
|
||||
"CURRENT_TIMESTAMP(%d) precision must not be negative",
|
||||
$3);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("CURRENT_TIMESTAMP(%d) precision must not be negative",
|
||||
$3)));
|
||||
if ($3 > MAX_TIMESTAMP_PRECISION)
|
||||
{
|
||||
elog(NOTICE,
|
||||
"CURRENT_TIMESTAMP(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_TIMESTAMP_PRECISION);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("CURRENT_TIMESTAMP(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_TIMESTAMP_PRECISION)));
|
||||
$3 = MAX_TIMESTAMP_PRECISION;
|
||||
}
|
||||
d->typmod = $3;
|
||||
@@ -6376,14 +6430,16 @@ c_expr: columnref { $$ = (Node *) $1; }
|
||||
s->typename = SystemTypeName("text");
|
||||
d = SystemTypeName("time");
|
||||
if ($3 < 0)
|
||||
elog(ERROR,
|
||||
"LOCALTIME(%d) precision must not be negative",
|
||||
$3);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("LOCALTIME(%d) precision must not be negative",
|
||||
$3)));
|
||||
if ($3 > MAX_TIME_PRECISION)
|
||||
{
|
||||
elog(NOTICE,
|
||||
"LOCALTIME(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_TIME_PRECISION);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("LOCALTIME(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_TIME_PRECISION)));
|
||||
$3 = MAX_TIME_PRECISION;
|
||||
}
|
||||
d->typmod = $3;
|
||||
@@ -6428,14 +6484,16 @@ c_expr: columnref { $$ = (Node *) $1; }
|
||||
|
||||
d = SystemTypeName("timestamp");
|
||||
if ($3 < 0)
|
||||
elog(ERROR,
|
||||
"LOCALTIMESTAMP(%d) precision must not be negative",
|
||||
$3);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("LOCALTIMESTAMP(%d) precision must not be negative",
|
||||
$3)));
|
||||
if ($3 > MAX_TIMESTAMP_PRECISION)
|
||||
{
|
||||
elog(NOTICE,
|
||||
"LOCALTIMESTAMP(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_TIMESTAMP_PRECISION);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("LOCALTIMESTAMP(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_TIMESTAMP_PRECISION)));
|
||||
$3 = MAX_TIMESTAMP_PRECISION;
|
||||
}
|
||||
d->typmod = $3;
|
||||
@@ -7020,10 +7078,10 @@ qualified_name:
|
||||
$$->relname = strVal(lthird($1));
|
||||
break;
|
||||
default:
|
||||
elog(ERROR,
|
||||
"Improper qualified name "
|
||||
"(too many dotted names): %s",
|
||||
NameListToString($1));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("improper qualified name (too many dotted names): %s",
|
||||
NameListToString($1))));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -7126,14 +7184,16 @@ AexprConst: Iconst
|
||||
n->val.val.str = $5;
|
||||
/* precision specified, and fields may be... */
|
||||
if ($3 < 0)
|
||||
elog(ERROR,
|
||||
"INTERVAL(%d) precision must not be negative",
|
||||
$3);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("INTERVAL(%d) precision must not be negative",
|
||||
$3)));
|
||||
if ($3 > MAX_INTERVAL_PRECISION)
|
||||
{
|
||||
elog(NOTICE,
|
||||
"INTERVAL(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_INTERVAL_PRECISION);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
|
||||
$3, MAX_INTERVAL_PRECISION)));
|
||||
$3 = MAX_INTERVAL_PRECISION;
|
||||
}
|
||||
n->typename->typmod = INTERVAL_TYPMOD($3, $6);
|
||||
@@ -7571,14 +7631,18 @@ SpecialRuleRelation:
|
||||
if (QueryIsRule)
|
||||
$$ = "*OLD*";
|
||||
else
|
||||
elog(ERROR, "OLD used in non-rule query");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("OLD used in non-rule query")));
|
||||
}
|
||||
| NEW
|
||||
{
|
||||
if (QueryIsRule)
|
||||
$$ = "*NEW*";
|
||||
else
|
||||
elog(ERROR, "NEW used in non-rule query");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("NEW used in non-rule query")));
|
||||
}
|
||||
;
|
||||
|
||||
@@ -7698,7 +7762,9 @@ makeRowExpr(List *opr, List *largs, List *rargs)
|
||||
char *oprname;
|
||||
|
||||
if (length(largs) != length(rargs))
|
||||
elog(ERROR, "Unequal number of entries in row expression");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("unequal number of entries in row expression")));
|
||||
|
||||
if (lnext(largs) != NIL)
|
||||
expr = makeRowExpr(opr, lnext(largs), lnext(rargs));
|
||||
@@ -7732,8 +7798,10 @@ makeRowExpr(List *opr, List *largs, List *rargs)
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(ERROR, "Operator '%s' not implemented for row expressions",
|
||||
oprname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("operator %s is not supported for row expressions",
|
||||
oprname)));
|
||||
}
|
||||
|
||||
return expr;
|
||||
@@ -7750,7 +7818,9 @@ makeDistinctExpr(List *largs, List *rargs)
|
||||
Node *larg, *rarg;
|
||||
|
||||
if (length(largs) != length(rargs))
|
||||
elog(ERROR, "Unequal number of entries in row expression");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("unequal number of entries in row expression")));
|
||||
|
||||
if (lnext(largs) != NIL)
|
||||
expr = makeDistinctExpr(lnext(largs), lnext(rargs));
|
||||
@@ -7805,13 +7875,15 @@ makeOverlaps(List *largs, List *rargs)
|
||||
if (length(largs) == 1)
|
||||
largs = lappend(largs, largs);
|
||||
else if (length(largs) != 2)
|
||||
elog(ERROR, "Wrong number of parameters"
|
||||
" on left side of OVERLAPS expression");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("wrong number of parameters on left side of OVERLAPS expression")));
|
||||
if (length(rargs) == 1)
|
||||
rargs = lappend(rargs, rargs);
|
||||
else if (length(rargs) != 2)
|
||||
elog(ERROR, "Wrong number of parameters"
|
||||
" on right side of OVERLAPS expression");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("wrong number of parameters on right side of OVERLAPS expression")));
|
||||
n->args = nconc(largs, rargs);
|
||||
n->agg_star = FALSE;
|
||||
n->agg_distinct = FALSE;
|
||||
@@ -7847,25 +7919,33 @@ insertSelectOptions(SelectStmt *stmt,
|
||||
if (sortClause)
|
||||
{
|
||||
if (stmt->sortClause)
|
||||
elog(ERROR, "Multiple ORDER BY clauses not allowed");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multiple ORDER BY clauses not allowed")));
|
||||
stmt->sortClause = sortClause;
|
||||
}
|
||||
if (forUpdate)
|
||||
{
|
||||
if (stmt->forUpdate)
|
||||
elog(ERROR, "Multiple FOR UPDATE clauses not allowed");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multiple FOR UPDATE clauses not allowed")));
|
||||
stmt->forUpdate = forUpdate;
|
||||
}
|
||||
if (limitOffset)
|
||||
{
|
||||
if (stmt->limitOffset)
|
||||
elog(ERROR, "Multiple OFFSET clauses not allowed");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multiple OFFSET clauses not allowed")));
|
||||
stmt->limitOffset = limitOffset;
|
||||
}
|
||||
if (limitCount)
|
||||
{
|
||||
if (stmt->limitCount)
|
||||
elog(ERROR, "Multiple LIMIT clauses not allowed");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multiple LIMIT clauses not allowed")));
|
||||
stmt->limitCount = limitCount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.54 2003/07/01 19:10:52 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.55 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -69,7 +69,9 @@ transformAggregateCall(ParseState *pstate, Aggref *agg)
|
||||
if (min_varlevel == 0)
|
||||
{
|
||||
if (checkExprHasAggs((Node *) agg->target))
|
||||
elog(ERROR, "aggregate function calls may not be nested");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("aggregate function calls may not be nested")));
|
||||
}
|
||||
|
||||
if (min_varlevel < 0)
|
||||
@@ -113,9 +115,13 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
|
||||
* problem is in WHERE.)
|
||||
*/
|
||||
if (checkExprHasAggs(qry->jointree->quals))
|
||||
elog(ERROR, "Aggregates not allowed in WHERE clause");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("aggregates not allowed in WHERE clause")));
|
||||
if (checkExprHasAggs((Node *) qry->jointree->fromlist))
|
||||
elog(ERROR, "Aggregates not allowed in JOIN conditions");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("aggregates not allowed in JOIN conditions")));
|
||||
|
||||
/*
|
||||
* No aggregates allowed in GROUP BY clauses, either.
|
||||
@@ -134,7 +140,9 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
|
||||
if (expr == NULL)
|
||||
continue; /* probably cannot happen */
|
||||
if (checkExprHasAggs(expr))
|
||||
elog(ERROR, "Aggregates not allowed in GROUP BY clause");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("aggregates not allowed in GROUP BY clause")));
|
||||
groupClauses = lcons(expr, groupClauses);
|
||||
if (!IsA(expr, Var))
|
||||
have_non_var_grouping = true;
|
||||
@@ -291,11 +299,15 @@ check_ungrouped_columns_walker(Node *node,
|
||||
rte = rt_fetch(var->varno, context->pstate->p_rtable);
|
||||
attname = get_rte_attribute_name(rte, var->varattno);
|
||||
if (context->sublevels_up == 0)
|
||||
elog(ERROR, "Attribute %s.%s must be GROUPed or used in an aggregate function",
|
||||
rte->eref->aliasname, attname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("attribute \"%s.%s\" must be GROUPed or used in an aggregate function",
|
||||
rte->eref->aliasname, attname)));
|
||||
else
|
||||
elog(ERROR, "Sub-SELECT uses un-GROUPed attribute %s.%s from outer query",
|
||||
rte->eref->aliasname, attname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("sub-select uses un-GROUPed attribute \"%s.%s\" from outer query",
|
||||
rte->eref->aliasname, attname)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.117 2003/07/03 19:07:45 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.118 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -192,7 +192,7 @@ interpretInhOption(InhOption inhOpt)
|
||||
case INH_DEFAULT:
|
||||
return SQL_inheritance;
|
||||
}
|
||||
elog(ERROR, "Bogus InhOption value");
|
||||
elog(ERROR, "bogus InhOption value");
|
||||
return false; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
@@ -334,8 +334,10 @@ transformJoinOnClause(ParseState *pstate, JoinExpr *j,
|
||||
{
|
||||
if (!intMember(varno, containedRels))
|
||||
{
|
||||
elog(ERROR, "JOIN/ON clause refers to \"%s\", which is not part of JOIN",
|
||||
rt_fetch(varno, pstate->p_rtable)->eref->aliasname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("JOIN/ON clause refers to \"%s\", which is not part of JOIN",
|
||||
rt_fetch(varno, pstate->p_rtable)->eref->aliasname)));
|
||||
}
|
||||
}
|
||||
bms_free(clause_varnos);
|
||||
@@ -392,7 +394,9 @@ transformRangeSubselect(ParseState *pstate, RangeSubselect *r)
|
||||
* an unlabeled subselect.
|
||||
*/
|
||||
if (r->alias == NULL)
|
||||
elog(ERROR, "sub-select in FROM must have an alias");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("sub-select in FROM must have an alias")));
|
||||
|
||||
/*
|
||||
* Analyze and transform the subquery.
|
||||
@@ -400,20 +404,22 @@ transformRangeSubselect(ParseState *pstate, RangeSubselect *r)
|
||||
parsetrees = parse_sub_analyze(r->subquery, pstate);
|
||||
|
||||
/*
|
||||
* Check that we got something reasonable. Some of these conditions
|
||||
* Check that we got something reasonable. Most of these conditions
|
||||
* are probably impossible given restrictions of the grammar, but
|
||||
* check 'em anyway.
|
||||
*/
|
||||
if (length(parsetrees) != 1)
|
||||
elog(ERROR, "Unexpected parse analysis result for subselect in FROM");
|
||||
elog(ERROR, "unexpected parse analysis result for sub-select in FROM");
|
||||
query = (Query *) lfirst(parsetrees);
|
||||
if (query == NULL || !IsA(query, Query))
|
||||
elog(ERROR, "Unexpected parse analysis result for subselect in FROM");
|
||||
elog(ERROR, "unexpected parse analysis result for sub-select in FROM");
|
||||
|
||||
if (query->commandType != CMD_SELECT)
|
||||
elog(ERROR, "Expected SELECT query from subselect in FROM");
|
||||
elog(ERROR, "expected SELECT query from sub-select in FROM");
|
||||
if (query->resultRelation != 0 || query->into != NULL)
|
||||
elog(ERROR, "Subselect in FROM may not have SELECT INTO");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("sub-select in FROM may not have SELECT INTO")));
|
||||
|
||||
/*
|
||||
* The subquery cannot make use of any variables from FROM items created
|
||||
@@ -431,7 +437,9 @@ transformRangeSubselect(ParseState *pstate, RangeSubselect *r)
|
||||
if (pstate->p_namespace)
|
||||
{
|
||||
if (contain_vars_of_level((Node *) query, 1))
|
||||
elog(ERROR, "Subselect in FROM may not refer to other relations of same query level");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("sub-select in FROM may not refer to other relations of same query level")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -484,7 +492,9 @@ transformRangeFunction(ParseState *pstate, RangeFunction *r)
|
||||
if (pstate->p_namespace)
|
||||
{
|
||||
if (contain_vars_of_level(funcexpr, 0))
|
||||
elog(ERROR, "FROM function expression may not refer to other relations of same query level");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("function expression in FROM may not refer to other relations of same query level")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -494,7 +504,9 @@ transformRangeFunction(ParseState *pstate, RangeFunction *r)
|
||||
if (pstate->p_hasAggs)
|
||||
{
|
||||
if (checkExprHasAggs(funcexpr))
|
||||
elog(ERROR, "cannot use aggregate function in FROM function expression");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("cannot use aggregate function in function expression in FROM")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -617,7 +629,7 @@ transformFromClauseItem(ParseState *pstate, Node *n, List **containedRels)
|
||||
leftrti = ((JoinExpr *) j->larg)->rtindex;
|
||||
else
|
||||
{
|
||||
elog(ERROR, "transformFromClauseItem: unexpected subtree type");
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(j->larg));
|
||||
leftrti = 0; /* keep compiler quiet */
|
||||
}
|
||||
rte = rt_fetch(leftrti, pstate->p_rtable);
|
||||
@@ -629,7 +641,7 @@ transformFromClauseItem(ParseState *pstate, Node *n, List **containedRels)
|
||||
rightrti = ((JoinExpr *) j->rarg)->rtindex;
|
||||
else
|
||||
{
|
||||
elog(ERROR, "transformFromClauseItem: unexpected subtree type");
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(j->rarg));
|
||||
rightrti = 0; /* keep compiler quiet */
|
||||
}
|
||||
rte = rt_fetch(rightrti, pstate->p_rtable);
|
||||
@@ -712,7 +724,10 @@ transformFromClauseItem(ParseState *pstate, Node *n, List **containedRels)
|
||||
char *res_colname = strVal(lfirst(col));
|
||||
|
||||
if (strcmp(res_colname, u_colname) == 0)
|
||||
elog(ERROR, "USING column name \"%s\" appears more than once", u_colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_COLUMN),
|
||||
errmsg("USING column name \"%s\" appears more than once",
|
||||
u_colname)));
|
||||
}
|
||||
|
||||
/* Find it in left input */
|
||||
@@ -724,14 +739,19 @@ transformFromClauseItem(ParseState *pstate, Node *n, List **containedRels)
|
||||
if (strcmp(l_colname, u_colname) == 0)
|
||||
{
|
||||
if (l_index >= 0)
|
||||
elog(ERROR, "Common column name \"%s\" appears more than once in left table", u_colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_COLUMN),
|
||||
errmsg("common column name \"%s\" appears more than once in left table",
|
||||
u_colname)));
|
||||
l_index = ndx;
|
||||
}
|
||||
ndx++;
|
||||
}
|
||||
if (l_index < 0)
|
||||
elog(ERROR, "JOIN/USING column \"%s\" not found in left table",
|
||||
u_colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("JOIN/USING column \"%s\" not found in left table",
|
||||
u_colname)));
|
||||
|
||||
/* Find it in right input */
|
||||
ndx = 0;
|
||||
@@ -742,14 +762,19 @@ transformFromClauseItem(ParseState *pstate, Node *n, List **containedRels)
|
||||
if (strcmp(r_colname, u_colname) == 0)
|
||||
{
|
||||
if (r_index >= 0)
|
||||
elog(ERROR, "Common column name \"%s\" appears more than once in right table", u_colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_COLUMN),
|
||||
errmsg("common column name \"%s\" appears more than once in right table",
|
||||
u_colname)));
|
||||
r_index = ndx;
|
||||
}
|
||||
ndx++;
|
||||
}
|
||||
if (r_index < 0)
|
||||
elog(ERROR, "JOIN/USING column \"%s\" not found in right table",
|
||||
u_colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("JOIN/USING column \"%s\" not found in right table",
|
||||
u_colname)));
|
||||
|
||||
l_colvar = nth(l_index, l_colvars);
|
||||
l_usingvars = lappend(l_usingvars, l_colvar);
|
||||
@@ -798,8 +823,10 @@ transformFromClauseItem(ParseState *pstate, Node *n, List **containedRels)
|
||||
if (j->alias->colnames != NIL)
|
||||
{
|
||||
if (length(j->alias->colnames) > length(res_colnames))
|
||||
elog(ERROR, "Column alias list for \"%s\" has too many entries",
|
||||
j->alias->aliasname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("column alias list for \"%s\" has too many entries",
|
||||
j->alias->aliasname)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -825,10 +852,8 @@ transformFromClauseItem(ParseState *pstate, Node *n, List **containedRels)
|
||||
return (Node *) j;
|
||||
}
|
||||
else
|
||||
elog(ERROR, "transformFromClauseItem: unexpected node (internal error)"
|
||||
"\n\t%s", nodeToString(n));
|
||||
return NULL; /* can't get here, just keep compiler
|
||||
* quiet */
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(n));
|
||||
return NULL; /* can't get here, keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -930,8 +955,7 @@ buildMergedJoinVar(ParseState *pstate, JoinType jointype,
|
||||
break;
|
||||
}
|
||||
default:
|
||||
elog(ERROR, "buildMergedJoinVar: unexpected jointype %d",
|
||||
(int) jointype);
|
||||
elog(ERROR, "unrecognized join type: %d", (int) jointype);
|
||||
res_node = NULL; /* keep compiler quiet */
|
||||
break;
|
||||
}
|
||||
@@ -991,21 +1015,27 @@ transformLimitClause(ParseState *pstate, Node *clause,
|
||||
*/
|
||||
if (contain_vars_of_level(qual, 0))
|
||||
{
|
||||
/* translator: %s is name of a SQL construct, eg LIMIT */
|
||||
elog(ERROR, "argument of %s must not contain variables",
|
||||
constructName);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
/* translator: %s is name of a SQL construct, eg LIMIT */
|
||||
errmsg("argument of %s must not contain variables",
|
||||
constructName)));
|
||||
}
|
||||
if (checkExprHasAggs(qual))
|
||||
{
|
||||
/* translator: %s is name of a SQL construct, eg LIMIT */
|
||||
elog(ERROR, "argument of %s must not contain aggregates",
|
||||
constructName);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
/* translator: %s is name of a SQL construct, eg LIMIT */
|
||||
errmsg("argument of %s must not contain aggregates",
|
||||
constructName)));
|
||||
}
|
||||
if (contain_subplans(qual))
|
||||
{
|
||||
/* translator: %s is name of a SQL construct, eg LIMIT */
|
||||
elog(ERROR, "argument of %s must not contain subselects",
|
||||
constructName);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
/* translator: %s is name of a SQL construct, eg LIMIT */
|
||||
errmsg("argument of %s must not contain sub-selects",
|
||||
constructName)));
|
||||
}
|
||||
|
||||
return qual;
|
||||
@@ -1083,7 +1113,7 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
|
||||
* is a matching column. If so, fall through to let
|
||||
* transformExpr() do the rest. NOTE: if name could refer
|
||||
* ambiguously to more than one column name exposed by FROM,
|
||||
* colnameToVar will elog(ERROR). That's just what we want
|
||||
* colnameToVar will ereport(ERROR). That's just what we want
|
||||
* here.
|
||||
*/
|
||||
if (colnameToVar(pstate, name) != NULL)
|
||||
@@ -1103,8 +1133,11 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
|
||||
if (target_result != NULL)
|
||||
{
|
||||
if (!equal(target_result->expr, tle->expr))
|
||||
elog(ERROR, "%s '%s' is ambiguous",
|
||||
clauseText[clause], name);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_COLUMN),
|
||||
/* translator: first %s is name of a SQL construct, eg ORDER BY */
|
||||
errmsg("%s \"%s\" is ambiguous",
|
||||
clauseText[clause], name)));
|
||||
}
|
||||
else
|
||||
target_result = tle;
|
||||
@@ -1122,7 +1155,11 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
|
||||
int target_pos;
|
||||
|
||||
if (!IsA(val, Integer))
|
||||
elog(ERROR, "Non-integer constant in %s", clauseText[clause]);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
/* translator: %s is name of a SQL construct, eg ORDER BY */
|
||||
errmsg("non-integer constant in %s",
|
||||
clauseText[clause])));
|
||||
target_pos = intVal(val);
|
||||
foreach(tl, tlist)
|
||||
{
|
||||
@@ -1135,8 +1172,11 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
|
||||
return tle; /* return the unique match */
|
||||
}
|
||||
}
|
||||
elog(ERROR, "%s position %d is not in target list",
|
||||
clauseText[clause], target_pos);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
/* translator: %s is name of a SQL construct, eg ORDER BY */
|
||||
errmsg("%s position %d is not in target list",
|
||||
clauseText[clause], target_pos)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1316,7 +1356,9 @@ transformDistinctClause(ParseState *pstate, List *distinctlist,
|
||||
TargetEntry *tle = get_sortgroupclause_tle(scl, targetlist);
|
||||
|
||||
if (tle->resdom->resjunk)
|
||||
elog(ERROR, "For SELECT DISTINCT, ORDER BY expressions must appear in target list");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("for SELECT DISTINCT, ORDER BY expressions must appear in target list")));
|
||||
else
|
||||
result = lappend(result, copyObject(scl));
|
||||
}
|
||||
@@ -1354,7 +1396,9 @@ transformDistinctClause(ParseState *pstate, List *distinctlist,
|
||||
SortClause *scl = (SortClause *) lfirst(nextsortlist);
|
||||
|
||||
if (tle->resdom->ressortgroupref != scl->tleSortGroupRef)
|
||||
elog(ERROR, "SELECT DISTINCT ON expressions must match initial ORDER BY expressions");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("SELECT DISTINCT ON expressions must match initial ORDER BY expressions")));
|
||||
result = lappend(result, copyObject(scl));
|
||||
nextsortlist = lnext(nextsortlist);
|
||||
}
|
||||
@@ -1378,8 +1422,8 @@ transformDistinctClause(ParseState *pstate, List *distinctlist,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (slitem == NIL)
|
||||
elog(ERROR, "transformDistinctClause: failed to add DISTINCT ON clause to target list");
|
||||
if (slitem == NIL) /* should not happen */
|
||||
elog(ERROR, "failed to add DISTINCT ON clause to target list");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.104 2003/07/18 23:20:32 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.105 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -44,7 +44,7 @@ static Node *coerce_type_typmod(Node *node,
|
||||
* cases (eg, when the conversion is expected to succeed).
|
||||
*
|
||||
* Returns the possibly-transformed expression tree, or NULL if the type
|
||||
* conversion is not possible. (We do this, rather than elog'ing directly,
|
||||
* conversion is not possible. (We do this, rather than ereport'ing directly,
|
||||
* so that callers can generate custom error messages indicating context.)
|
||||
*
|
||||
* pstate - parse state (can be NULL, see coerce_type)
|
||||
@@ -248,7 +248,7 @@ coerce_type(ParseState *pstate, Node *node,
|
||||
(errcode(ERRCODE_AMBIGUOUS_PARAMETER),
|
||||
errmsg("inconsistent types deduced for parameter $%d",
|
||||
paramno),
|
||||
errdetail("Could be either %s or %s.",
|
||||
errdetail("%s versus %s",
|
||||
format_type_be(toppstate->p_paramtypes[paramno-1]),
|
||||
format_type_be(targetTypeId))));
|
||||
}
|
||||
@@ -330,7 +330,7 @@ coerce_type(ParseState *pstate, Node *node,
|
||||
cformat);
|
||||
}
|
||||
/* If we get here, caller blew it */
|
||||
elog(ERROR, "coerce_type: no conversion function from %s to %s",
|
||||
elog(ERROR, "failed to find conversion function from %s to %s",
|
||||
format_type_be(inputTypeId), format_type_be(targetTypeId));
|
||||
return NULL; /* keep compiler quiet */
|
||||
}
|
||||
@@ -566,19 +566,19 @@ coerce_to_boolean(ParseState *pstate, Node *node,
|
||||
COERCION_ASSIGNMENT,
|
||||
COERCE_IMPLICIT_CAST);
|
||||
if (node == NULL)
|
||||
{
|
||||
/* translator: first %s is name of a SQL construct, eg WHERE */
|
||||
elog(ERROR, "argument of %s must be type boolean, not type %s",
|
||||
constructName, format_type_be(inputTypeId));
|
||||
}
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
/* translator: first %s is name of a SQL construct, eg WHERE */
|
||||
errmsg("argument of %s must be type boolean, not type %s",
|
||||
constructName, format_type_be(inputTypeId))));
|
||||
}
|
||||
|
||||
if (expression_returns_set(node))
|
||||
{
|
||||
/* translator: %s is name of a SQL construct, eg WHERE */
|
||||
elog(ERROR, "argument of %s must not be a set function",
|
||||
constructName);
|
||||
}
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
/* translator: %s is name of a SQL construct, eg WHERE */
|
||||
errmsg("argument of %s must not return a set",
|
||||
constructName)));
|
||||
|
||||
return node;
|
||||
}
|
||||
@@ -605,19 +605,19 @@ coerce_to_integer(ParseState *pstate, Node *node,
|
||||
COERCION_ASSIGNMENT,
|
||||
COERCE_IMPLICIT_CAST);
|
||||
if (node == NULL)
|
||||
{
|
||||
/* translator: first %s is name of a SQL construct, eg LIMIT */
|
||||
elog(ERROR, "argument of %s must be type integer, not type %s",
|
||||
constructName, format_type_be(inputTypeId));
|
||||
}
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
/* translator: first %s is name of a SQL construct, eg LIMIT */
|
||||
errmsg("argument of %s must be type integer, not type %s",
|
||||
constructName, format_type_be(inputTypeId))));
|
||||
}
|
||||
|
||||
if (expression_returns_set(node))
|
||||
{
|
||||
/* translator: %s is name of a SQL construct, eg LIMIT */
|
||||
elog(ERROR, "argument of %s must not be a set function",
|
||||
constructName);
|
||||
}
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
/* translator: %s is name of a SQL construct, eg LIMIT */
|
||||
errmsg("argument of %s must not return a set",
|
||||
constructName)));
|
||||
|
||||
return node;
|
||||
}
|
||||
@@ -662,8 +662,13 @@ select_common_type(List *typeids, const char *context)
|
||||
* both types in different categories? then not much
|
||||
* hope...
|
||||
*/
|
||||
elog(ERROR, "%s types '%s' and '%s' not matched",
|
||||
context, format_type_be(ptype), format_type_be(ntype));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
/* translator: first %s is name of a SQL construct, eg CASE */
|
||||
errmsg("%s types %s and %s cannot be matched",
|
||||
context,
|
||||
format_type_be(ptype),
|
||||
format_type_be(ntype))));
|
||||
}
|
||||
else if (!IsPreferredType(pcategory, ptype) &&
|
||||
can_coerce_type(1, &ptype, &ntype, COERCION_IMPLICIT) &&
|
||||
@@ -718,8 +723,13 @@ coerce_to_common_type(ParseState *pstate, Node *node,
|
||||
node = coerce_type(pstate, node, inputTypeId, targetTypeId,
|
||||
COERCION_IMPLICIT, COERCE_IMPLICIT_CAST);
|
||||
else
|
||||
elog(ERROR, "%s unable to convert to type %s",
|
||||
context, format_type_be(targetTypeId));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_CANNOT_COERCE),
|
||||
/* translator: first %s is name of a SQL construct, eg CASE */
|
||||
errmsg("%s unable to convert type %s to %s",
|
||||
context,
|
||||
format_type_be(inputTypeId),
|
||||
format_type_be(targetTypeId))));
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -740,7 +750,7 @@ coerce_to_common_type(ParseState *pstate, Node *node,
|
||||
* If we have UNKNOWN input (ie, an untyped literal) for any ANYELEMENT
|
||||
* or ANYARRAY argument, assume it is okay.
|
||||
*
|
||||
* We do not elog here, but just return FALSE if a rule is violated.
|
||||
* We do not ereport here, but just return FALSE if a rule is violated.
|
||||
*/
|
||||
bool
|
||||
check_generic_type_consistency(Oid *actual_arg_types,
|
||||
@@ -870,9 +880,12 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
|
||||
continue;
|
||||
}
|
||||
if (OidIsValid(elem_typeid) && actual_type != elem_typeid)
|
||||
elog(ERROR, "Arguments declared ANYELEMENT are not all alike: %s vs %s",
|
||||
format_type_be(elem_typeid),
|
||||
format_type_be(actual_type));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("arguments declared ANYELEMENT are not all alike"),
|
||||
errdetail("%s versus %s",
|
||||
format_type_be(elem_typeid),
|
||||
format_type_be(actual_type))));
|
||||
elem_typeid = actual_type;
|
||||
}
|
||||
else if (declared_arg_types[j] == ANYARRAYOID)
|
||||
@@ -884,9 +897,12 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
|
||||
continue;
|
||||
}
|
||||
if (OidIsValid(array_typeid) && actual_type != array_typeid)
|
||||
elog(ERROR, "Arguments declared ANYARRAY are not all alike: %s vs %s",
|
||||
format_type_be(array_typeid),
|
||||
format_type_be(actual_type));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("arguments declared ANYARRAY are not all alike"),
|
||||
errdetail("%s versus %s",
|
||||
format_type_be(array_typeid),
|
||||
format_type_be(actual_type))));
|
||||
array_typeid = actual_type;
|
||||
}
|
||||
}
|
||||
@@ -903,8 +919,10 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
|
||||
{
|
||||
array_typelem = get_element_type(array_typeid);
|
||||
if (!OidIsValid(array_typelem))
|
||||
elog(ERROR, "Argument declared ANYARRAY is not an array: %s",
|
||||
format_type_be(array_typeid));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("argument declared ANYARRAY is not an array but %s",
|
||||
format_type_be(array_typeid))));
|
||||
|
||||
if (!OidIsValid(elem_typeid))
|
||||
{
|
||||
@@ -914,16 +932,20 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
|
||||
else if (array_typelem != elem_typeid)
|
||||
{
|
||||
/* otherwise, they better match */
|
||||
elog(ERROR, "Argument declared ANYARRAY is not consistent with "
|
||||
"argument declared ANYELEMENT: %s vs %s",
|
||||
format_type_be(array_typeid),
|
||||
format_type_be(elem_typeid));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("argument declared ANYARRAY is not consistent with argument declared ANYELEMENT"),
|
||||
errdetail("%s versus %s",
|
||||
format_type_be(array_typeid),
|
||||
format_type_be(elem_typeid))));
|
||||
}
|
||||
}
|
||||
else if (!OidIsValid(elem_typeid))
|
||||
{
|
||||
/* Only way to get here is if all the generic args are UNKNOWN */
|
||||
elog(ERROR, "Cannot determine ANYARRAY/ANYELEMENT type because input is UNKNOWN");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("cannot determine ANYARRAY/ANYELEMENT type because input is UNKNOWN")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -948,8 +970,10 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
|
||||
{
|
||||
array_typeid = get_array_type(elem_typeid);
|
||||
if (!OidIsValid(array_typeid))
|
||||
elog(ERROR, "Cannot find array type for datatype %s",
|
||||
format_type_be(elem_typeid));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("cannot find array type for datatype %s",
|
||||
format_type_be(elem_typeid))));
|
||||
}
|
||||
declared_arg_types[j] = array_typeid;
|
||||
}
|
||||
@@ -963,8 +987,10 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
|
||||
{
|
||||
array_typeid = get_array_type(elem_typeid);
|
||||
if (!OidIsValid(array_typeid))
|
||||
elog(ERROR, "Cannot find array type for datatype %s",
|
||||
format_type_be(elem_typeid));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("cannot find array type for datatype %s",
|
||||
format_type_be(elem_typeid))));
|
||||
}
|
||||
return array_typeid;
|
||||
}
|
||||
@@ -1003,8 +1029,10 @@ resolve_generic_type(Oid declared_type,
|
||||
Oid array_typelem = get_element_type(context_actual_type);
|
||||
|
||||
if (!OidIsValid(array_typelem))
|
||||
elog(ERROR, "Argument declared ANYARRAY is not an array: %s",
|
||||
format_type_be(context_actual_type));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("argument declared ANYARRAY is not an array but %s",
|
||||
format_type_be(context_actual_type))));
|
||||
return context_actual_type;
|
||||
}
|
||||
else if (context_declared_type == ANYELEMENTOID)
|
||||
@@ -1013,8 +1041,10 @@ resolve_generic_type(Oid declared_type,
|
||||
Oid array_typeid = get_array_type(context_actual_type);
|
||||
|
||||
if (!OidIsValid(array_typeid))
|
||||
elog(ERROR, "Cannot find array type for datatype %s",
|
||||
format_type_be(context_actual_type));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("cannot find array type for datatype %s",
|
||||
format_type_be(context_actual_type))));
|
||||
return array_typeid;
|
||||
}
|
||||
}
|
||||
@@ -1026,8 +1056,10 @@ resolve_generic_type(Oid declared_type,
|
||||
Oid array_typelem = get_element_type(context_actual_type);
|
||||
|
||||
if (!OidIsValid(array_typelem))
|
||||
elog(ERROR, "Argument declared ANYARRAY is not an array: %s",
|
||||
format_type_be(context_actual_type));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("argument declared ANYARRAY is not an array but %s",
|
||||
format_type_be(context_actual_type))));
|
||||
return array_typelem;
|
||||
}
|
||||
else if (context_declared_type == ANYELEMENTOID)
|
||||
@@ -1043,7 +1075,7 @@ resolve_generic_type(Oid declared_type,
|
||||
}
|
||||
/* If we get here, declared_type is polymorphic and context isn't */
|
||||
/* NB: this is a calling-code logic error, not a user error */
|
||||
elog(ERROR, "Cannot determine ANYARRAY/ANYELEMENT type because context isn't polymorphic");
|
||||
elog(ERROR, "cannot determine ANYARRAY/ANYELEMENT type because context isn't polymorphic");
|
||||
return InvalidOid; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
@@ -1234,7 +1266,7 @@ IsPreferredType(CATEGORY category, Oid type)
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "IsPreferredType: unknown category");
|
||||
elog(ERROR, "unrecognized type category: %d", (int) category);
|
||||
preftype = UNKNOWNOID;
|
||||
break;
|
||||
}
|
||||
@@ -1365,8 +1397,8 @@ find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
|
||||
castcontext = COERCION_EXPLICIT;
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "find_coercion_pathway: bogus castcontext %c",
|
||||
castForm->castcontext);
|
||||
elog(ERROR, "unrecognized castcontext: %d",
|
||||
(int) castForm->castcontext);
|
||||
castcontext = 0; /* keep compiler quiet */
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.156 2003/07/18 23:20:32 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.157 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -51,7 +51,7 @@ static Node *transformIndirection(ParseState *pstate, Node *basenode,
|
||||
* Initialize for parsing a new query.
|
||||
*
|
||||
* We reset the expression depth counter here, in case it was left nonzero
|
||||
* due to elog()'ing out of the last parsing operation.
|
||||
* due to ereport()'ing out of the last parsing operation.
|
||||
*/
|
||||
void
|
||||
parse_expr_init(void)
|
||||
@@ -100,8 +100,11 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
* to be able to crash the backend quite that easily...
|
||||
*/
|
||||
if (++expr_depth_counter > max_expr_depth)
|
||||
elog(ERROR, "Expression too complex: nesting depth exceeds max_expr_depth = %d",
|
||||
max_expr_depth);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
|
||||
errmsg("expression too complex"),
|
||||
errdetail("Nesting depth exceeds MAX_EXPR_DEPTH = %d.",
|
||||
max_expr_depth)));
|
||||
|
||||
switch (nodeTag(expr))
|
||||
{
|
||||
@@ -343,7 +346,9 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
lexpr,
|
||||
rexpr);
|
||||
if (((OpExpr *) result)->opresulttype != BOOLOID)
|
||||
elog(ERROR, "IS DISTINCT FROM requires = operator to yield boolean");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("IS DISTINCT FROM requires = operator to yield boolean")));
|
||||
/*
|
||||
* We rely on DistinctExpr and OpExpr being same struct
|
||||
*/
|
||||
@@ -362,7 +367,9 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
lexpr,
|
||||
rexpr);
|
||||
if (((OpExpr *) result)->opresulttype != BOOLOID)
|
||||
elog(ERROR, "NULLIF requires = operator to yield boolean");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("NULLIF requires = operator to yield boolean")));
|
||||
/*
|
||||
* We rely on NullIfExpr and OpExpr being same struct
|
||||
*/
|
||||
@@ -451,11 +458,11 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
pstate->p_hasSubLinks = true;
|
||||
qtrees = parse_sub_analyze(sublink->subselect, pstate);
|
||||
if (length(qtrees) != 1)
|
||||
elog(ERROR, "Bad query in subselect");
|
||||
elog(ERROR, "bad query in sub-select");
|
||||
qtree = (Query *) lfirst(qtrees);
|
||||
if (qtree->commandType != CMD_SELECT ||
|
||||
qtree->resultRelation != 0)
|
||||
elog(ERROR, "Bad query in subselect");
|
||||
elog(ERROR, "bad query in sub-select");
|
||||
sublink->subselect = (Node *) qtree;
|
||||
|
||||
if (sublink->subLinkType == EXISTS_SUBLINK)
|
||||
@@ -480,11 +487,15 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
*/
|
||||
if (tlist == NIL ||
|
||||
((TargetEntry *) lfirst(tlist))->resdom->resjunk)
|
||||
elog(ERROR, "Subselect must have a field");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("sub-select must return a column")));
|
||||
while ((tlist = lnext(tlist)) != NIL)
|
||||
{
|
||||
if (!((TargetEntry *) lfirst(tlist))->resdom->resjunk)
|
||||
elog(ERROR, "Subselect must have only one field");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("sub-select must return only one column")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -536,8 +547,10 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
if (row_length != 1 &&
|
||||
strcmp(opname, "=") != 0 &&
|
||||
strcmp(opname, "<>") != 0)
|
||||
elog(ERROR, "Row comparison cannot use operator %s",
|
||||
opname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("row comparison cannot use operator %s",
|
||||
opname)));
|
||||
|
||||
/*
|
||||
* To build the list of combining operator OIDs, we must
|
||||
@@ -561,7 +574,9 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
continue;
|
||||
|
||||
if (left_list == NIL)
|
||||
elog(ERROR, "Subselect has too many fields");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("sub-select has too many columns")));
|
||||
lexpr = lfirst(left_list);
|
||||
left_list = lnext(left_list);
|
||||
|
||||
@@ -577,15 +592,19 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
opform = (Form_pg_operator) GETSTRUCT(optup);
|
||||
|
||||
if (opform->oprresult != BOOLOID)
|
||||
elog(ERROR, "%s has result type of %s, but must return %s"
|
||||
" to be used with quantified predicate subquery",
|
||||
opname, format_type_be(opform->oprresult),
|
||||
format_type_be(BOOLOID));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("operator %s must return boolean, not type %s",
|
||||
opname,
|
||||
format_type_be(opform->oprresult)),
|
||||
errhint("The operator of a quantified predicate subquery must return boolean.")));
|
||||
|
||||
if (get_func_retset(opform->oprcode))
|
||||
elog(ERROR, "%s must not return a set"
|
||||
" to be used with quantified predicate subquery",
|
||||
opname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("operator %s must not return a set",
|
||||
opname),
|
||||
errhint("The operator of a quantified predicate subquery must return boolean.")));
|
||||
|
||||
sublink->operOids = lappendo(sublink->operOids,
|
||||
oprid(optup));
|
||||
@@ -593,7 +612,9 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
ReleaseSysCache(optup);
|
||||
}
|
||||
if (left_list != NIL)
|
||||
elog(ERROR, "Subselect has too few fields");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("sub-select has too few columns")));
|
||||
|
||||
if (needNot)
|
||||
{
|
||||
@@ -762,8 +783,10 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
array_type = element_type;
|
||||
element_type = get_element_type(array_type);
|
||||
if (!OidIsValid(element_type))
|
||||
elog(ERROR, "Cannot find array type for datatype %s",
|
||||
format_type_be(array_type));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("cannot find array type for datatype %s",
|
||||
format_type_be(array_type))));
|
||||
|
||||
/*
|
||||
* make sure the element expressions all have the same
|
||||
@@ -775,15 +798,19 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
ArrayExpr *e = (ArrayExpr *) lfirst(element);
|
||||
|
||||
if (!IsA(e, ArrayExpr))
|
||||
elog(ERROR, "Multidimensional ARRAY[] must be built from nested array expressions");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("multidimensional ARRAY[] must be built from nested array expressions")));
|
||||
if (ndims == 0)
|
||||
ndims = e->ndims;
|
||||
else if (e->ndims != ndims)
|
||||
elog(ERROR, "Nested array expressions must have "
|
||||
"common number of dimensions");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("nested array expressions must have common number of dimensions")));
|
||||
if (e->element_typeid != element_type)
|
||||
elog(ERROR, "Nested array expressions must have "
|
||||
"common element type");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("nested array expressions must have common element type")));
|
||||
|
||||
}
|
||||
/* increment the number of dimensions */
|
||||
@@ -791,9 +818,10 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
|
||||
/* make sure we don't have too many dimensions now */
|
||||
if (ndims > MAXDIM)
|
||||
elog(ERROR, "Number of array dimensions, %d, "
|
||||
"exceeds the maximum allowed %d",
|
||||
ndims, MAXDIM);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("number of array dimensions exceeds the maximum allowed, %d",
|
||||
MAXDIM)));
|
||||
}
|
||||
|
||||
newa->array_typeid = array_type;
|
||||
@@ -879,7 +907,7 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
clausename = "IS NOT UNKNOWN";
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "transformExpr: unexpected booltesttype %d",
|
||||
elog(ERROR, "unrecognized booltesttype: %d",
|
||||
(int) b->booltesttype);
|
||||
clausename = NULL; /* keep compiler quiet */
|
||||
}
|
||||
@@ -925,8 +953,7 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
|
||||
default:
|
||||
/* should not reach here */
|
||||
elog(ERROR, "transformExpr: does not know how to transform node %d"
|
||||
" (internal error)", nodeTag(expr));
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1030,7 +1057,9 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
|
||||
node = (Node *) rv;
|
||||
}
|
||||
else
|
||||
elog(ERROR, "Attribute \"%s\" not found", name);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("attribute \"%s\" not found", name)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1112,7 +1141,9 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
|
||||
* We check the catalog name and then ignore it.
|
||||
*/
|
||||
if (strcmp(name1, get_database_name(MyDatabaseId)) != 0)
|
||||
elog(ERROR, "Cross-database references are not implemented");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cross-database references are not implemented")));
|
||||
|
||||
/* Whole-row reference? */
|
||||
if (strcmp(name4, "*") == 0)
|
||||
@@ -1142,7 +1173,10 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
elog(ERROR, "Invalid qualified name syntax (too many names)");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("improper qualified name (too many dotted names): %s",
|
||||
NameListToString(cref->fields))));
|
||||
node = NULL; /* keep compiler quiet */
|
||||
break;
|
||||
}
|
||||
@@ -1206,7 +1240,7 @@ exprType(Node *expr)
|
||||
TargetEntry *tent;
|
||||
|
||||
if (!qtree || !IsA(qtree, Query))
|
||||
elog(ERROR, "exprType: Cannot get type for untransformed sublink");
|
||||
elog(ERROR, "cannot get type for untransformed sublink");
|
||||
tent = (TargetEntry *) lfirst(qtree->targetList);
|
||||
Assert(IsA(tent, TargetEntry));
|
||||
Assert(!tent->resdom->resjunk);
|
||||
@@ -1216,8 +1250,10 @@ exprType(Node *expr)
|
||||
{
|
||||
type = get_array_type(tent->resdom->restype);
|
||||
if (!OidIsValid(type))
|
||||
elog(ERROR, "Cannot find array type for datatype %s",
|
||||
format_type_be(tent->resdom->restype));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("cannot find array type for datatype %s",
|
||||
format_type_be(tent->resdom->restype))));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1251,8 +1287,10 @@ exprType(Node *expr)
|
||||
{
|
||||
type = get_array_type(tent->resdom->restype);
|
||||
if (!OidIsValid(type))
|
||||
elog(ERROR, "Cannot find array type for datatype %s",
|
||||
format_type_be(tent->resdom->restype));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("cannot find array type for datatype %s",
|
||||
format_type_be(tent->resdom->restype))));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1304,13 +1342,14 @@ exprType(Node *expr)
|
||||
* we will likely first notice a problem here (see comments in
|
||||
* transformColumnRef()). Issue an appropriate error message.
|
||||
*/
|
||||
elog(ERROR, "Relation reference \"%s\" cannot be used in an expression",
|
||||
((RangeVar *) expr)->relname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("relation reference \"%s\" cannot be used in an expression",
|
||||
((RangeVar *) expr)->relname)));
|
||||
type = InvalidOid; /* keep compiler quiet */
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "exprType: Do not know how to get type for %d node",
|
||||
nodeTag(expr));
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
|
||||
type = InvalidOid; /* keep compiler quiet */
|
||||
break;
|
||||
}
|
||||
@@ -1511,9 +1550,11 @@ typecast_expression(ParseState *pstate, Node *expr, TypeName *typename)
|
||||
COERCION_EXPLICIT,
|
||||
COERCE_EXPLICIT_CAST);
|
||||
if (expr == NULL)
|
||||
elog(ERROR, "Cannot cast type %s to %s",
|
||||
format_type_be(inputType),
|
||||
format_type_be(targetType));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_CANNOT_COERCE),
|
||||
errmsg("cannot cast type %s to %s",
|
||||
format_type_be(inputType),
|
||||
format_type_be(targetType))));
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.154 2003/07/18 23:20:32 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.155 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -179,7 +179,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
||||
case RTE_RELATION:
|
||||
toid = get_rel_type_id(rte->relid);
|
||||
if (!OidIsValid(toid))
|
||||
elog(ERROR, "cannot find type OID for relation %u",
|
||||
elog(ERROR, "could not find type OID for relation %u",
|
||||
rte->relid);
|
||||
/* replace RangeVar in the arg list */
|
||||
lfirst(i) = makeVar(vnum,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.78 2003/04/29 22:13:10 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.79 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -114,14 +114,15 @@ transformArraySubscripts(ParseState *pstate,
|
||||
ObjectIdGetDatum(arrayType),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(type_tuple_array))
|
||||
elog(ERROR, "transformArraySubscripts: Cache lookup failed for array type %u",
|
||||
arrayType);
|
||||
elog(ERROR, "cache lookup failed for type %u", arrayType);
|
||||
type_struct_array = (Form_pg_type) GETSTRUCT(type_tuple_array);
|
||||
|
||||
elementType = type_struct_array->typelem;
|
||||
if (elementType == InvalidOid)
|
||||
elog(ERROR, "transformArraySubscripts: type %s is not an array",
|
||||
NameStr(type_struct_array->typname));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("cannot subscript type %s because it is not an array",
|
||||
format_type_be(arrayType))));
|
||||
|
||||
/*
|
||||
* A list containing only single subscripts refers to a single array
|
||||
@@ -177,7 +178,9 @@ transformArraySubscripts(ParseState *pstate,
|
||||
COERCION_ASSIGNMENT,
|
||||
COERCE_IMPLICIT_CAST);
|
||||
if (subexpr == NULL)
|
||||
elog(ERROR, "array index expressions must be integers");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("array subscript must have type integer")));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -198,7 +201,9 @@ transformArraySubscripts(ParseState *pstate,
|
||||
COERCION_ASSIGNMENT,
|
||||
COERCE_IMPLICIT_CAST);
|
||||
if (subexpr == NULL)
|
||||
elog(ERROR, "array index expressions must be integers");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("array subscript must have type integer")));
|
||||
upperIndexpr = lappend(upperIndexpr, subexpr);
|
||||
}
|
||||
|
||||
@@ -218,11 +223,13 @@ transformArraySubscripts(ParseState *pstate,
|
||||
COERCION_ASSIGNMENT,
|
||||
COERCE_IMPLICIT_CAST);
|
||||
if (assignFrom == NULL)
|
||||
elog(ERROR, "Array assignment requires type %s"
|
||||
" but expression is of type %s"
|
||||
"\n\tYou will need to rewrite or cast the expression",
|
||||
format_type_be(typeneeded),
|
||||
format_type_be(typesource));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("array assignment requires type %s"
|
||||
" but expression is of type %s",
|
||||
format_type_be(typeneeded),
|
||||
format_type_be(typesource)),
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,18 +330,18 @@ make_const(Value *value)
|
||||
typebyval = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(WARNING, "make_const: unknown type %d", nodeTag(value));
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case T_Null:
|
||||
/* return a null const */
|
||||
con = makeConst(UNKNOWNOID,
|
||||
-1,
|
||||
(Datum) NULL,
|
||||
(Datum) 0,
|
||||
true,
|
||||
false);
|
||||
return con;
|
||||
|
||||
default:
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(value));
|
||||
return NULL; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
con = makeConst(typeid,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.83 2003/06/15 17:59:10 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.84 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -62,7 +62,8 @@ static void warnAutoRange(ParseState *pstate, RangeVar *relation);
|
||||
* An unqualified refname (schemaname == NULL) can match any RTE with matching
|
||||
* alias, or matching unqualified relname in the case of alias-less relation
|
||||
* RTEs. It is possible that such a refname matches multiple RTEs in the
|
||||
* nearest nesting level that has a match; if so, we report an error via elog.
|
||||
* nearest nesting level that has a match; if so, we report an error via
|
||||
* ereport().
|
||||
*
|
||||
* A qualified refname (schemaname != NULL) can only match a relation RTE
|
||||
* that (a) has no alias and (b) is for the same relation identified by
|
||||
@@ -168,7 +169,10 @@ scanNameSpaceForRefname(ParseState *pstate, Node *nsnode,
|
||||
if (!result)
|
||||
result = newresult;
|
||||
else if (newresult)
|
||||
elog(ERROR, "Table reference \"%s\" is ambiguous", refname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_ALIAS),
|
||||
errmsg("table reference \"%s\" is ambiguous",
|
||||
refname)));
|
||||
}
|
||||
else if (IsA(nsnode, List))
|
||||
{
|
||||
@@ -180,12 +184,14 @@ scanNameSpaceForRefname(ParseState *pstate, Node *nsnode,
|
||||
if (!result)
|
||||
result = newresult;
|
||||
else if (newresult)
|
||||
elog(ERROR, "Table reference \"%s\" is ambiguous", refname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_ALIAS),
|
||||
errmsg("table reference \"%s\" is ambiguous",
|
||||
refname)));
|
||||
}
|
||||
}
|
||||
else
|
||||
elog(ERROR, "scanNameSpaceForRefname: unexpected node type %d",
|
||||
nodeTag(nsnode));
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(nsnode));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -238,7 +244,10 @@ scanNameSpaceForRelid(ParseState *pstate, Node *nsnode, Oid relid)
|
||||
if (!result)
|
||||
result = newresult;
|
||||
else if (newresult)
|
||||
elog(ERROR, "Table reference %u is ambiguous", relid);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_ALIAS),
|
||||
errmsg("table reference %u is ambiguous",
|
||||
relid)));
|
||||
}
|
||||
else if (IsA(nsnode, List))
|
||||
{
|
||||
@@ -250,12 +259,14 @@ scanNameSpaceForRelid(ParseState *pstate, Node *nsnode, Oid relid)
|
||||
if (!result)
|
||||
result = newresult;
|
||||
else if (newresult)
|
||||
elog(ERROR, "Table reference %u is ambiguous", relid);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_ALIAS),
|
||||
errmsg("table reference %u is ambiguous",
|
||||
relid)));
|
||||
}
|
||||
}
|
||||
else
|
||||
elog(ERROR, "scanNameSpaceForRelid: unexpected node type %d",
|
||||
nodeTag(nsnode));
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(nsnode));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -318,8 +329,7 @@ checkNameSpaceConflicts(ParseState *pstate, Node *namespace1,
|
||||
checkNameSpaceConflicts(pstate, lfirst(l), namespace2);
|
||||
}
|
||||
else
|
||||
elog(ERROR, "checkNameSpaceConflicts: unexpected node type %d",
|
||||
nodeTag(namespace1));
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(namespace1));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -341,8 +351,10 @@ scanNameSpaceForConflict(ParseState *pstate, Node *nsnode,
|
||||
if (rte->rtekind == RTE_RELATION && rte->alias == NULL &&
|
||||
rte1 != NULL && rte->relid != rte1->relid)
|
||||
return; /* no conflict per SQL92 rule */
|
||||
elog(ERROR, "Table name \"%s\" specified more than once",
|
||||
aliasname1);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_ALIAS),
|
||||
errmsg("table name \"%s\" specified more than once",
|
||||
aliasname1)));
|
||||
}
|
||||
else if (IsA(nsnode, JoinExpr))
|
||||
{
|
||||
@@ -351,8 +363,10 @@ scanNameSpaceForConflict(ParseState *pstate, Node *nsnode,
|
||||
if (j->alias)
|
||||
{
|
||||
if (strcmp(j->alias->aliasname, aliasname1) == 0)
|
||||
elog(ERROR, "Table name \"%s\" specified more than once",
|
||||
aliasname1);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_ALIAS),
|
||||
errmsg("table name \"%s\" specified more than once",
|
||||
aliasname1)));
|
||||
|
||||
/*
|
||||
* Tables within an aliased join are invisible from outside
|
||||
@@ -372,8 +386,7 @@ scanNameSpaceForConflict(ParseState *pstate, Node *nsnode,
|
||||
scanNameSpaceForConflict(pstate, lfirst(l), rte1, aliasname1);
|
||||
}
|
||||
else
|
||||
elog(ERROR, "scanNameSpaceForConflict: unexpected node type %d",
|
||||
nodeTag(nsnode));
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(nsnode));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -407,7 +420,7 @@ RTERangeTablePosn(ParseState *pstate, RangeTblEntry *rte, int *sublevels_up)
|
||||
break;
|
||||
}
|
||||
|
||||
elog(ERROR, "RTERangeTablePosn: RTE not found (internal error)");
|
||||
elog(ERROR, "RTE not found (internal error)");
|
||||
return 0; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
@@ -459,7 +472,10 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname)
|
||||
get_rte_attribute_is_dropped(rte, attnum))
|
||||
continue;
|
||||
if (result)
|
||||
elog(ERROR, "Column reference \"%s\" is ambiguous", colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_COLUMN),
|
||||
errmsg("column reference \"%s\" is ambiguous",
|
||||
colname)));
|
||||
result = (Node *) make_var(pstate, rte, attnum);
|
||||
rte->checkForRead = true;
|
||||
}
|
||||
@@ -546,14 +562,16 @@ colnameToVar(ParseState *pstate, char *colname)
|
||||
newresult = scanRTEForColumn(orig_pstate, rte, colname);
|
||||
}
|
||||
else
|
||||
elog(ERROR, "colnameToVar: unexpected node type %d",
|
||||
nodeTag(nsnode));
|
||||
elog(ERROR, "unrecognized node type: %d",
|
||||
(int) nodeTag(nsnode));
|
||||
|
||||
if (newresult)
|
||||
{
|
||||
if (result)
|
||||
elog(ERROR, "Column reference \"%s\" is ambiguous",
|
||||
colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_AMBIGUOUS_COLUMN),
|
||||
errmsg("column reference \"%s\" is ambiguous",
|
||||
colname)));
|
||||
result = newresult;
|
||||
}
|
||||
}
|
||||
@@ -645,8 +663,10 @@ addRangeTableEntry(ParseState *pstate,
|
||||
*/
|
||||
maxattrs = RelationGetNumberOfAttributes(rel);
|
||||
if (maxattrs < numaliases)
|
||||
elog(ERROR, "Table \"%s\" has %d columns available but %d columns specified",
|
||||
RelationGetRelationName(rel), maxattrs, numaliases);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("table \"%s\" has %d columns available but %d columns specified",
|
||||
RelationGetRelationName(rel), maxattrs, numaliases)));
|
||||
|
||||
/* fill in any unspecified alias columns using actual column names */
|
||||
for (varattno = numaliases; varattno < maxattrs; varattno++)
|
||||
@@ -738,8 +758,10 @@ addRangeTableEntryForRelation(ParseState *pstate,
|
||||
*/
|
||||
maxattrs = RelationGetNumberOfAttributes(rel);
|
||||
if (maxattrs < numaliases)
|
||||
elog(ERROR, "Table \"%s\" has %d columns available but %d columns specified",
|
||||
RelationGetRelationName(rel), maxattrs, numaliases);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("table \"%s\" has %d columns available but %d columns specified",
|
||||
RelationGetRelationName(rel), maxattrs, numaliases)));
|
||||
|
||||
/* fill in any unspecified alias columns using actual column names */
|
||||
for (varattno = numaliases; varattno < maxattrs; varattno++)
|
||||
@@ -831,8 +853,10 @@ addRangeTableEntryForSubquery(ParseState *pstate,
|
||||
}
|
||||
}
|
||||
if (varattno < numaliases)
|
||||
elog(ERROR, "Table \"%s\" has %d columns available but %d columns specified",
|
||||
refname, varattno, numaliases);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("table \"%s\" has %d columns available but %d columns specified",
|
||||
refname, varattno, numaliases)));
|
||||
|
||||
rte->eref = eref;
|
||||
|
||||
@@ -906,7 +930,9 @@ addRangeTableEntryForFunction(ParseState *pstate,
|
||||
* pseudo-type
|
||||
*/
|
||||
if (funcrettype != RECORDOID)
|
||||
elog(ERROR, "A column definition list is only allowed for functions returning RECORD");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("a column definition list is only allowed for functions returning RECORD")));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -915,7 +941,9 @@ addRangeTableEntryForFunction(ParseState *pstate,
|
||||
* RECORD pseudo-type
|
||||
*/
|
||||
if (funcrettype == RECORDOID)
|
||||
elog(ERROR, "A column definition list is required for functions returning RECORD");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("a column definition list is required for functions returning RECORD")));
|
||||
}
|
||||
|
||||
functyptype = get_typtype(funcrettype);
|
||||
@@ -929,9 +957,8 @@ addRangeTableEntryForFunction(ParseState *pstate,
|
||||
Relation rel;
|
||||
int maxattrs;
|
||||
|
||||
if (!OidIsValid(funcrelid))
|
||||
elog(ERROR, "Invalid typrelid for complex type %u",
|
||||
funcrettype);
|
||||
if (!OidIsValid(funcrelid)) /* shouldn't happen if typtype is 'c' */
|
||||
elog(ERROR, "invalid typrelid for complex type %u", funcrettype);
|
||||
|
||||
/*
|
||||
* Get the rel's relcache entry. This access ensures that we have
|
||||
@@ -945,8 +972,11 @@ addRangeTableEntryForFunction(ParseState *pstate,
|
||||
*/
|
||||
maxattrs = RelationGetNumberOfAttributes(rel);
|
||||
if (maxattrs < numaliases)
|
||||
elog(ERROR, "Table \"%s\" has %d columns available but %d columns specified",
|
||||
RelationGetRelationName(rel), maxattrs, numaliases);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("table \"%s\" has %d columns available but %d columns specified",
|
||||
RelationGetRelationName(rel),
|
||||
maxattrs, numaliases)));
|
||||
|
||||
/* fill in alias columns using actual column names */
|
||||
for (varattno = numaliases; varattno < maxattrs; varattno++)
|
||||
@@ -971,8 +1001,10 @@ addRangeTableEntryForFunction(ParseState *pstate,
|
||||
* column named for the function.
|
||||
*/
|
||||
if (numaliases > 1)
|
||||
elog(ERROR, "Too many column aliases specified for function %s",
|
||||
funcname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
|
||||
errmsg("too many column aliases specified for function %s",
|
||||
funcname)));
|
||||
if (numaliases == 0)
|
||||
eref->colnames = makeList1(makeString(eref->aliasname));
|
||||
}
|
||||
@@ -992,8 +1024,10 @@ addRangeTableEntryForFunction(ParseState *pstate,
|
||||
}
|
||||
}
|
||||
else
|
||||
elog(ERROR, "function %s() in FROM has unsupported return type",
|
||||
funcname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("function \"%s\" in FROM has unsupported return type",
|
||||
funcname)));
|
||||
|
||||
/*----------
|
||||
* Flags:
|
||||
@@ -1284,8 +1318,8 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte,
|
||||
int maxattrs;
|
||||
int numaliases;
|
||||
|
||||
if (!OidIsValid(funcrelid))
|
||||
elog(ERROR, "Invalid typrelid for complex type %u",
|
||||
if (!OidIsValid(funcrelid)) /* shouldn't happen */
|
||||
elog(ERROR, "invalid typrelid for complex type %u",
|
||||
funcrettype);
|
||||
|
||||
rel = relation_open(funcrelid, AccessShareLock);
|
||||
@@ -1382,7 +1416,9 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte,
|
||||
}
|
||||
}
|
||||
else
|
||||
elog(ERROR, "function in FROM has unsupported return type");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("function in FROM has unsupported return type")));
|
||||
}
|
||||
break;
|
||||
case RTE_JOIN:
|
||||
@@ -1424,8 +1460,7 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte,
|
||||
}
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "expandRTE: unsupported RTE kind %d",
|
||||
(int) rte->rtekind);
|
||||
elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1502,7 +1537,7 @@ get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
|
||||
{
|
||||
attname = get_attname(rte->relid, attnum);
|
||||
if (attname == NULL)
|
||||
elog(ERROR, "cache lookup of attribute %d in relation %u failed",
|
||||
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
|
||||
attnum, rte->relid);
|
||||
return attname;
|
||||
}
|
||||
@@ -1514,7 +1549,8 @@ get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
|
||||
if (attnum > 0 && attnum <= length(rte->eref->colnames))
|
||||
return strVal(nth(attnum - 1, rte->eref->colnames));
|
||||
|
||||
elog(ERROR, "Invalid attnum %d for rangetable entry %s",
|
||||
/* else caller gave us a bogus attnum */
|
||||
elog(ERROR, "invalid attnum %d for rangetable entry %s",
|
||||
attnum, rte->eref->aliasname);
|
||||
return NULL; /* keep compiler quiet */
|
||||
}
|
||||
@@ -1539,10 +1575,9 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
ObjectIdGetDatum(rte->relid),
|
||||
Int16GetDatum(attnum),
|
||||
0, 0);
|
||||
/* this shouldn't happen... */
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "Relation \"%s\" does not have attribute %d",
|
||||
get_rel_name(rte->relid), attnum);
|
||||
if (!HeapTupleIsValid(tp)) /* shouldn't happen */
|
||||
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
|
||||
attnum, rte->relid);
|
||||
att_tup = (Form_pg_attribute) GETSTRUCT(tp);
|
||||
|
||||
/*
|
||||
@@ -1550,8 +1585,11 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
* in scanRTEForColumn.
|
||||
*/
|
||||
if (att_tup->attisdropped)
|
||||
elog(ERROR, "Relation \"%s\" has no column \"%s\"",
|
||||
get_rel_name(rte->relid), NameStr(att_tup->attname));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("relation \"%s\" has no column \"%s\"",
|
||||
get_rel_name(rte->relid),
|
||||
NameStr(att_tup->attname))));
|
||||
*vartype = att_tup->atttypid;
|
||||
*vartypmod = att_tup->atttypmod;
|
||||
ReleaseSysCache(tp);
|
||||
@@ -1573,7 +1611,7 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
return;
|
||||
}
|
||||
/* falling off end of list shouldn't happen... */
|
||||
elog(ERROR, "Subquery %s does not have attribute %d",
|
||||
elog(ERROR, "subquery %s does not have attribute %d",
|
||||
rte->eref->aliasname, attnum);
|
||||
}
|
||||
break;
|
||||
@@ -1594,18 +1632,17 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
HeapTuple tp;
|
||||
Form_pg_attribute att_tup;
|
||||
|
||||
if (!OidIsValid(funcrelid))
|
||||
elog(ERROR, "Invalid typrelid for complex type %u",
|
||||
if (!OidIsValid(funcrelid)) /* shouldn't happen */
|
||||
elog(ERROR, "invalid typrelid for complex type %u",
|
||||
funcrettype);
|
||||
|
||||
tp = SearchSysCache(ATTNUM,
|
||||
ObjectIdGetDatum(funcrelid),
|
||||
Int16GetDatum(attnum),
|
||||
0, 0);
|
||||
/* this shouldn't happen... */
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "Relation \"%s\" does not have attribute %d",
|
||||
get_rel_name(funcrelid), attnum);
|
||||
if (!HeapTupleIsValid(tp)) /* shouldn't happen */
|
||||
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
|
||||
attnum, funcrelid);
|
||||
att_tup = (Form_pg_attribute) GETSTRUCT(tp);
|
||||
|
||||
/*
|
||||
@@ -1613,9 +1650,11 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
* notes in scanRTEForColumn.
|
||||
*/
|
||||
if (att_tup->attisdropped)
|
||||
elog(ERROR, "Relation \"%s\" has no column \"%s\"",
|
||||
get_rel_name(funcrelid),
|
||||
NameStr(att_tup->attname));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("relation \"%s\" has no column \"%s\"",
|
||||
get_rel_name(funcrelid),
|
||||
NameStr(att_tup->attname))));
|
||||
*vartype = att_tup->atttypid;
|
||||
*vartypmod = att_tup->atttypmod;
|
||||
ReleaseSysCache(tp);
|
||||
@@ -1636,7 +1675,9 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
*vartypmod = -1;
|
||||
}
|
||||
else
|
||||
elog(ERROR, "function in FROM has unsupported return type");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("function in FROM has unsupported return type")));
|
||||
}
|
||||
break;
|
||||
case RTE_JOIN:
|
||||
@@ -1654,8 +1695,7 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
}
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "get_rte_attribute_type: unsupported RTE kind %d",
|
||||
(int) rte->rtekind);
|
||||
elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1680,10 +1720,9 @@ get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
|
||||
ObjectIdGetDatum(rte->relid),
|
||||
Int16GetDatum(attnum),
|
||||
0, 0);
|
||||
/* this shouldn't happen... */
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "Relation \"%s\" does not have attribute %d",
|
||||
get_rel_name(rte->relid), attnum);
|
||||
if (!HeapTupleIsValid(tp)) /* shouldn't happen */
|
||||
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
|
||||
attnum, rte->relid);
|
||||
att_tup = (Form_pg_attribute) GETSTRUCT(tp);
|
||||
result = att_tup->attisdropped;
|
||||
ReleaseSysCache(tp);
|
||||
@@ -1713,10 +1752,9 @@ get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
|
||||
ObjectIdGetDatum(funcrelid),
|
||||
Int16GetDatum(attnum),
|
||||
0, 0);
|
||||
/* this shouldn't happen... */
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "Relation %s does not have attribute %d",
|
||||
get_rel_name(funcrelid), attnum);
|
||||
if (!HeapTupleIsValid(tp)) /* shouldn't happen */
|
||||
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
|
||||
attnum, funcrelid);
|
||||
att_tup = (Form_pg_attribute) GETSTRUCT(tp);
|
||||
result = att_tup->attisdropped;
|
||||
ReleaseSysCache(tp);
|
||||
@@ -1731,8 +1769,7 @@ get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "get_rte_attribute_is_dropped: unsupported RTE kind %d",
|
||||
(int) rte->rtekind);
|
||||
elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind);
|
||||
result = false; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
@@ -1769,9 +1806,11 @@ attnameAttNum(Relation rd, const char *attname, bool sysColOK)
|
||||
}
|
||||
|
||||
/* on failure */
|
||||
elog(ERROR, "Relation \"%s\" has no column \"%s\"",
|
||||
RelationGetRelationName(rd), attname);
|
||||
return InvalidAttrNumber; /* lint */
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("relation \"%s\" has no column \"%s\"",
|
||||
RelationGetRelationName(rd), attname)));
|
||||
return InvalidAttrNumber; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/* specialAttNum()
|
||||
@@ -1814,7 +1853,7 @@ attnumAttName(Relation rd, int attid)
|
||||
return &sysatt->attname;
|
||||
}
|
||||
if (attid > rd->rd_att->natts)
|
||||
elog(ERROR, "attnumAttName: invalid attribute number %d", attid);
|
||||
elog(ERROR, "invalid attribute number %d", attid);
|
||||
return &rd->rd_att->attrs[attid - 1]->attname;
|
||||
}
|
||||
|
||||
@@ -1836,14 +1875,16 @@ attnumTypeId(Relation rd, int attid)
|
||||
return sysatt->atttypid;
|
||||
}
|
||||
if (attid > rd->rd_att->natts)
|
||||
elog(ERROR, "attnumTypeId: invalid attribute number %d", attid);
|
||||
elog(ERROR, "invalid attribute number %d", attid);
|
||||
return rd->rd_att->attrs[attid - 1]->atttypid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate a warning about an implicit RTE, if appropriate.
|
||||
* Generate a warning or error about an implicit RTE, if appropriate.
|
||||
*
|
||||
* Our current theory on this is that we should allow "SELECT foo.*"
|
||||
* If ADD_MISSING_FROM is not enabled, raise an error.
|
||||
*
|
||||
* Our current theory on warnings is that we should allow "SELECT foo.*"
|
||||
* but warn about a mixture of explicit and implicit RTEs.
|
||||
*/
|
||||
static void
|
||||
@@ -1852,6 +1893,20 @@ warnAutoRange(ParseState *pstate, RangeVar *relation)
|
||||
bool foundInFromCl = false;
|
||||
List *temp;
|
||||
|
||||
if (!add_missing_from)
|
||||
{
|
||||
if (pstate->parentParseState != NULL)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_TABLE),
|
||||
errmsg("missing FROM-clause entry in subquery for table \"%s\"",
|
||||
relation->relname)));
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_TABLE),
|
||||
errmsg("missing FROM-clause entry for table \"%s\"",
|
||||
relation->relname)));
|
||||
}
|
||||
|
||||
foreach(temp, pstate->p_rtable)
|
||||
{
|
||||
RangeTblEntry *rte = lfirst(temp);
|
||||
@@ -1864,13 +1919,15 @@ warnAutoRange(ParseState *pstate, RangeVar *relation)
|
||||
}
|
||||
if (foundInFromCl)
|
||||
{
|
||||
if (add_missing_from)
|
||||
elog(NOTICE, "Adding missing FROM-clause entry%s for table \"%s\"",
|
||||
pstate->parentParseState != NULL ? " in subquery" : "",
|
||||
relation->relname);
|
||||
if (pstate->parentParseState != NULL)
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_UNDEFINED_TABLE),
|
||||
errmsg("adding missing FROM-clause entry in subquery for table \"%s\"",
|
||||
relation->relname)));
|
||||
else
|
||||
elog(ERROR, "Missing FROM-clause entry%s for table \"%s\"",
|
||||
pstate->parentParseState != NULL ? " in subquery" : "",
|
||||
relation->relname);
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_UNDEFINED_TABLE),
|
||||
errmsg("adding missing FROM-clause entry for table \"%s\"",
|
||||
relation->relname)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.106 2003/07/03 16:34:20 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.107 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -61,7 +61,12 @@ transformTargetEntry(ParseState *pstate,
|
||||
expr = transformExpr(pstate, node);
|
||||
|
||||
if (IsA(expr, RangeVar))
|
||||
elog(ERROR, "You can't use relation names alone in the target list, try relation.*.");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("relation reference \"%s\" cannot be used as a targetlist entry",
|
||||
((RangeVar *) expr)->relname),
|
||||
errhint("Write \"%s\".* to denote all the columns of the relation.",
|
||||
((RangeVar *) expr)->relname)));
|
||||
|
||||
type_id = exprType(expr);
|
||||
type_mod = exprTypmod(expr);
|
||||
@@ -146,13 +151,18 @@ transformTargetList(ParseState *pstate, List *targetlist)
|
||||
* it.
|
||||
*/
|
||||
if (strcmp(name1, get_database_name(MyDatabaseId)) != 0)
|
||||
elog(ERROR, "Cross-database references are not implemented");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cross-database references are not implemented")));
|
||||
schemaname = strVal(lsecond(fields));
|
||||
relname = strVal(lthird(fields));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
elog(ERROR, "Invalid qualified name syntax (too many names)");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("improper qualified name (too many dotted names): %s",
|
||||
NameListToString(fields))));
|
||||
schemaname = NULL; /* keep compiler quiet */
|
||||
relname = NULL;
|
||||
break;
|
||||
@@ -269,7 +279,7 @@ markTargetListOrigin(ParseState *pstate, Resdom *res, Var *var)
|
||||
}
|
||||
/* falling off end of list shouldn't happen... */
|
||||
if (subtl == NIL)
|
||||
elog(ERROR, "Subquery %s does not have attribute %d",
|
||||
elog(ERROR, "subquery %s does not have attribute %d",
|
||||
rte->eref->aliasname, attnum);
|
||||
}
|
||||
break;
|
||||
@@ -320,7 +330,10 @@ updateTargetListEntry(ParseState *pstate,
|
||||
|
||||
Assert(rd != NULL);
|
||||
if (attrno <= 0)
|
||||
elog(ERROR, "Cannot assign to system attribute '%s'", colname);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot assign to system attribute \"%s\"",
|
||||
colname)));
|
||||
attrtype = attnumTypeId(rd, attrno);
|
||||
attrtypmod = rd->rd_att->attrs[attrno - 1]->atttypmod;
|
||||
|
||||
@@ -339,7 +352,9 @@ updateTargetListEntry(ParseState *pstate,
|
||||
def->typeId = attrtype;
|
||||
def->typeMod = attrtypmod;
|
||||
if (indirection)
|
||||
elog(ERROR, "cannot set an array element to DEFAULT");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot set an array element to DEFAULT")));
|
||||
}
|
||||
|
||||
/* Now we can use exprType() safely. */
|
||||
@@ -404,12 +419,14 @@ updateTargetListEntry(ParseState *pstate,
|
||||
COERCION_ASSIGNMENT,
|
||||
COERCE_IMPLICIT_CAST);
|
||||
if (tle->expr == NULL)
|
||||
elog(ERROR, "column \"%s\" is of type %s"
|
||||
" but expression is of type %s"
|
||||
"\n\tYou will need to rewrite or cast the expression",
|
||||
colname,
|
||||
format_type_be(attrtype),
|
||||
format_type_be(type_id));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("column \"%s\" is of type %s"
|
||||
" but expression is of type %s",
|
||||
colname,
|
||||
format_type_be(attrtype),
|
||||
format_type_be(type_id)),
|
||||
errhint("You will need to rewrite or cast the expression.")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,11 +490,14 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
|
||||
char *name = ((ResTarget *) lfirst(tl))->name;
|
||||
int attrno;
|
||||
|
||||
/* Lookup column name, elog on failure */
|
||||
/* Lookup column name, ereport on failure */
|
||||
attrno = attnameAttNum(pstate->p_target_relation, name, false);
|
||||
/* Check for duplicates */
|
||||
if (intMember(attrno, *attrnos))
|
||||
elog(ERROR, "Attribute '%s' specified more than once", name);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_COLUMN),
|
||||
errmsg("attribute \"%s\" specified more than once in INSERT list",
|
||||
name)));
|
||||
*attrnos = lappendi(*attrnos, attrno);
|
||||
}
|
||||
}
|
||||
@@ -512,8 +532,7 @@ ExpandAllTables(ParseState *pstate)
|
||||
pstate->p_rtable);
|
||||
else
|
||||
{
|
||||
elog(ERROR, "ExpandAllTables: unexpected node (internal error)"
|
||||
"\n\t%s", nodeToString(n));
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(n));
|
||||
rte = NULL; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
@@ -530,7 +549,9 @@ ExpandAllTables(ParseState *pstate)
|
||||
|
||||
/* Check for SELECT *; */
|
||||
if (!found_table)
|
||||
elog(ERROR, "Wildcard with no tables specified not allowed");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("SELECT * with no tables specified is not valid")));
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.57 2003/04/29 22:13:10 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.58 2003/07/19 20:20:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -57,8 +57,10 @@ LookupTypeName(const TypeName *typename)
|
||||
switch (length(typename->names))
|
||||
{
|
||||
case 1:
|
||||
elog(ERROR, "Improper %%TYPE reference (too few dotted names): %s",
|
||||
NameListToString(typename->names));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("improper %%TYPE reference (too few dotted names): %s",
|
||||
NameListToString(typename->names))));
|
||||
break;
|
||||
case 2:
|
||||
rel->relname = strVal(lfirst(typename->names));
|
||||
@@ -76,8 +78,10 @@ LookupTypeName(const TypeName *typename)
|
||||
field = strVal(lfourth(typename->names));
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "Improper %%TYPE reference (too many dotted names): %s",
|
||||
NameListToString(typename->names));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("improper %%TYPE reference (too many dotted names): %s",
|
||||
NameListToString(typename->names))));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -85,16 +89,20 @@ LookupTypeName(const TypeName *typename)
|
||||
relid = RangeVarGetRelid(rel, false);
|
||||
attnum = get_attnum(relid, field);
|
||||
if (attnum == InvalidAttrNumber)
|
||||
elog(ERROR, "Relation \"%s\" has no column \"%s\"",
|
||||
rel->relname, field);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("relation \"%s\" has no column \"%s\"",
|
||||
rel->relname, field)));
|
||||
restype = get_atttype(relid, attnum);
|
||||
|
||||
/* this construct should never have an array indicator */
|
||||
Assert(typename->arrayBounds == NIL);
|
||||
|
||||
/* emit nuisance warning */
|
||||
elog(NOTICE, "%s converted to %s",
|
||||
TypeNameToString(typename), format_type_be(restype));
|
||||
/* emit nuisance notice */
|
||||
ereport(NOTICE,
|
||||
(errmsg("type reference %s converted to %s",
|
||||
TypeNameToString(typename),
|
||||
format_type_be(restype))));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -188,11 +196,15 @@ typenameTypeId(const TypeName *typename)
|
||||
|
||||
typoid = LookupTypeName(typename);
|
||||
if (!OidIsValid(typoid))
|
||||
elog(ERROR, "Type \"%s\" does not exist",
|
||||
TypeNameToString(typename));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("type \"%s\" does not exist",
|
||||
TypeNameToString(typename))));
|
||||
if (!get_typisdefined(typoid))
|
||||
elog(ERROR, "Type \"%s\" is only a shell",
|
||||
TypeNameToString(typename));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("type \"%s\" is only a shell",
|
||||
TypeNameToString(typename))));
|
||||
return typoid;
|
||||
}
|
||||
|
||||
@@ -210,17 +222,20 @@ typenameType(const TypeName *typename)
|
||||
|
||||
typoid = LookupTypeName(typename);
|
||||
if (!OidIsValid(typoid))
|
||||
elog(ERROR, "Type \"%s\" does not exist",
|
||||
TypeNameToString(typename));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("type \"%s\" does not exist",
|
||||
TypeNameToString(typename))));
|
||||
tup = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(typoid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "Type \"%s\" does not exist",
|
||||
TypeNameToString(typename));
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for type %u", typoid);
|
||||
if (!((Form_pg_type) GETSTRUCT(tup))->typisdefined)
|
||||
elog(ERROR, "Type \"%s\" is only a shell",
|
||||
TypeNameToString(typename));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("type \"%s\" is only a shell",
|
||||
TypeNameToString(typename))));
|
||||
return (Type) tup;
|
||||
}
|
||||
|
||||
@@ -244,7 +259,7 @@ typeidType(Oid id)
|
||||
ObjectIdGetDatum(id),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "Unable to locate type oid %u in catalog", id);
|
||||
elog(ERROR, "cache lookup failed for type %u", id);
|
||||
return (Type) tup;
|
||||
}
|
||||
|
||||
@@ -252,7 +267,7 @@ typeidType(Oid id)
|
||||
Oid
|
||||
typeTypeId(Type tp)
|
||||
{
|
||||
if (tp == NULL)
|
||||
if (tp == NULL) /* probably useless */
|
||||
elog(ERROR, "typeTypeId() called with NULL type struct");
|
||||
return HeapTupleGetOid(tp);
|
||||
}
|
||||
@@ -386,7 +401,7 @@ typeidOutfunc(Oid type_id)
|
||||
ObjectIdGetDatum(type_id),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "typeidOutfunc: Invalid type - oid = %u", type_id);
|
||||
elog(ERROR, "cache lookup failed for type %u", type_id);
|
||||
|
||||
type = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
outfunc = type->typoutput;
|
||||
@@ -407,7 +422,7 @@ typeidTypeRelid(Oid type_id)
|
||||
ObjectIdGetDatum(type_id),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "typeidTypeRelid: Invalid type - oid = %u", type_id);
|
||||
elog(ERROR, "cache lookup failed for type %u", type_id);
|
||||
|
||||
type = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
result = type->typrelid;
|
||||
@@ -444,7 +459,7 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod)
|
||||
* paranoia is justified since the string might contain anything.
|
||||
*/
|
||||
if (length(raw_parsetree_list) != 1)
|
||||
elog(ERROR, "Invalid type name '%s'", str);
|
||||
goto fail;
|
||||
stmt = (SelectStmt *) lfirst(raw_parsetree_list);
|
||||
if (stmt == NULL ||
|
||||
!IsA(stmt, SelectStmt) ||
|
||||
@@ -459,28 +474,35 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod)
|
||||
stmt->limitCount != NULL ||
|
||||
stmt->forUpdate != NIL ||
|
||||
stmt->op != SETOP_NONE)
|
||||
elog(ERROR, "Invalid type name '%s'", str);
|
||||
goto fail;
|
||||
if (length(stmt->targetList) != 1)
|
||||
elog(ERROR, "Invalid type name '%s'", str);
|
||||
goto fail;
|
||||
restarget = (ResTarget *) lfirst(stmt->targetList);
|
||||
if (restarget == NULL ||
|
||||
!IsA(restarget, ResTarget) ||
|
||||
restarget->name != NULL ||
|
||||
restarget->indirection != NIL)
|
||||
elog(ERROR, "Invalid type name '%s'", str);
|
||||
goto fail;
|
||||
typecast = (TypeCast *) restarget->val;
|
||||
if (typecast == NULL ||
|
||||
!IsA(typecast, TypeCast) ||
|
||||
typecast->arg == NULL ||
|
||||
!IsA(typecast->arg, A_Const))
|
||||
elog(ERROR, "Invalid type name '%s'", str);
|
||||
goto fail;
|
||||
typename = typecast->typename;
|
||||
if (typename == NULL ||
|
||||
!IsA(typename, TypeName))
|
||||
elog(ERROR, "Invalid type name '%s'", str);
|
||||
goto fail;
|
||||
|
||||
*type_id = typenameTypeId(typename);
|
||||
*typmod = typename->typmod;
|
||||
|
||||
pfree(buf.data);
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("invalid type name \"%s\"", str)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user