Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/heap.c10
-rw-r--r--src/backend/catalog/pg_proc.c24
-rw-r--r--src/backend/commands/indexcmds.c12
-rw-r--r--src/backend/parser/parse_agg.c7
-rw-r--r--src/backend/parser/parse_clause.c15
-rw-r--r--src/backend/parser/parse_expr.c26
-rw-r--r--src/backend/parser/parse_func.c7
-rw-r--r--src/backend/parser/parse_node.c6
-rw-r--r--src/backend/parser/parse_oper.c37
-rw-r--r--src/backend/parser/parse_target.c9
-rw-r--r--src/backend/utils/adt/format_type.c39
11 files changed, 117 insertions, 75 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 02e29441da2..3f80f92aed5 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.171 2001/07/15 22:48:17 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.172 2001/08/09 18:28:16 petere Exp $
*
*
* INTERFACE ROUTINES
@@ -1668,12 +1668,12 @@ AddRelationRawConstraints(Relation rel,
{
if (CoerceTargetExpr(NULL, expr, type_id,
atp->atttypid, atp->atttypmod) == NULL)
- elog(ERROR, "Attribute '%s' is of type '%s'"
- " but default expression is of type '%s'"
+ elog(ERROR, "Column \"%s\" is of type %s"
+ " but default expression is of type %s"
"\n\tYou will need to rewrite or cast the expression",
NameStr(atp->attname),
- typeidTypeName(atp->atttypid),
- typeidTypeName(type_id));
+ format_type_be(atp->atttypid),
+ format_type_be(type_id));
}
}
diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c
index a71aa8e5e77..ad3727e15f1 100644
--- a/src/backend/catalog/pg_proc.c
+++ b/src/backend/catalog/pg_proc.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.55 2001/03/22 06:16:10 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.56 2001/08/09 18:28:17 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -343,7 +343,7 @@ checkretval(Oid rettype, List *queryTreeList)
{
if (rettype != InvalidOid)
elog(ERROR, "function declared to return %s, but no SELECT provided",
- typeidTypeName(rettype));
+ format_type_be(rettype));
return;
}
@@ -360,14 +360,14 @@ checkretval(Oid rettype, List *queryTreeList)
if (rettype == InvalidOid)
{
if (cmd == CMD_SELECT)
- elog(ERROR, "function declared with no return type, but final query is a SELECT");
+ elog(ERROR, "function declared with no return type, but final statement is a SELECT");
return;
}
/* by here, the function is declared to return some type */
if (cmd != CMD_SELECT)
- elog(ERROR, "function declared to return %s, but final query is not a SELECT",
- typeidTypeName(rettype));
+ elog(ERROR, "function declared to return %s, but final statement is not a SELECT",
+ format_type_be(rettype));
/*
* Count the non-junk entries in the result targetlist.
@@ -383,12 +383,12 @@ checkretval(Oid rettype, List *queryTreeList)
{
if (tlistlen != 1)
elog(ERROR, "function declared to return %s returns multiple columns in final SELECT",
- typeidTypeName(rettype));
+ format_type_be(rettype));
resnode = (Resdom *) ((TargetEntry *) lfirst(tlist))->resdom;
if (resnode->restype != rettype)
elog(ERROR, "return type mismatch in function: declared to return %s, returns %s",
- typeidTypeName(rettype), typeidTypeName(resnode->restype));
+ format_type_be(rettype), format_type_be(resnode->restype));
return;
}
@@ -419,7 +419,7 @@ checkretval(Oid rettype, List *queryTreeList)
if (tlistlen != relnatts)
elog(ERROR, "function declared to return %s does not SELECT the right number of columns (%d)",
- typeidTypeName(rettype), relnatts);
+ format_type_be(rettype), relnatts);
/* expect attributes 1 .. n in order */
i = 0;
@@ -433,9 +433,9 @@ checkretval(Oid rettype, List *queryTreeList)
tletype = exprType(tle->expr);
if (tletype != reln->rd_att->attrs[i]->atttypid)
elog(ERROR, "function declared to return %s returns %s instead of %s at column %d",
- typeidTypeName(rettype),
- typeidTypeName(tletype),
- typeidTypeName(reln->rd_att->attrs[i]->atttypid),
+ format_type_be(rettype),
+ format_type_be(tletype),
+ format_type_be(reln->rd_att->attrs[i]->atttypid),
i + 1);
i++;
}
@@ -443,7 +443,7 @@ checkretval(Oid rettype, List *queryTreeList)
/* this shouldn't happen, but let's just check... */
if (i != relnatts)
elog(ERROR, "function declared to return %s does not SELECT the right number of columns (%d)",
- typeidTypeName(rettype), relnatts);
+ format_type_be(rettype), relnatts);
heap_close(reln, AccessShareLock);
}
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 094ddefcc7b..f5f815f1954 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.54 2001/08/06 18:09:45 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.55 2001/08/09 18:28:17 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -403,8 +403,10 @@ GetAttrOpClass(IndexElem *attribute, Oid attrType,
/* no operator class specified, so find the default */
attribute->class = GetDefaultOpClass(attrType);
if (attribute->class == NULL)
- elog(ERROR, "DefineIndex: type %s has no default operator class",
- typeidTypeName(attrType));
+ elog(ERROR, "data type %s has no default operator class"
+ "\n\tYou must specify an operator class for the index or define a"
+ "\n\tdefault operator class for the data type",
+ format_type_be(attrType));
/* assume we need not check type compatibility */
doTypeCheck = false;
}
@@ -468,8 +470,8 @@ GetAttrOpClass(IndexElem *attribute, Oid attrType,
if (attrType != opInputType &&
!IS_BINARY_COMPATIBLE(attrType, opInputType))
- elog(ERROR, "DefineIndex: opclass \"%s\" does not accept datatype \"%s\"",
- attribute->class, typeidTypeName(attrType));
+ elog(ERROR, "operator class \"%s\" does not accept data type %s",
+ attribute->class, format_type_be(attrType));
ReleaseSysCache(tuple);
}
}
diff --git a/src/backend/parser/parse_agg.c b/src/backend/parser/parse_agg.c
index f1dd56f0bca..3c621ddc699 100644
--- a/src/backend/parser/parse_agg.c
+++ b/src/backend/parser/parse_agg.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.44 2001/01/24 19:43:01 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.45 2001/08/09 18:28:17 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,6 +22,7 @@
#include "parser/parse_expr.h"
#include "parser/parsetree.h"
#include "parser/parse_type.h"
+#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
@@ -249,6 +250,6 @@ agg_error(char *caller, char *aggname, Oid basetypeID)
elog(ERROR, "%s: aggregate '%s' for all types does not exist",
caller, aggname);
else
- elog(ERROR, "%s: aggregate '%s' for '%s' does not exist",
- caller, aggname, typeidTypeName(basetypeID));
+ elog(ERROR, "%s: aggregate '%s' for type %s does not exist",
+ caller, aggname, format_type_be(basetypeID));
}
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c
index 585b21b0f45..e8ba26295e7 100644
--- a/src/backend/parser/parse_clause.c
+++ b/src/backend/parser/parse_clause.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.81 2001/06/19 22:39:11 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.82 2001/08/09 18:28:17 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -29,6 +29,7 @@
#include "parser/parse_relation.h"
#include "parser/parse_target.h"
#include "parser/parse_type.h"
+#include "utils/builtins.h"
#include "utils/guc.h"
@@ -292,8 +293,8 @@ transformJoinUsingClause(ParseState *pstate, List *leftVars, List *rightVars)
* "=" operator that doesn't return bool is wrong anyway.
*/
if (exprType(result) != BOOLOID)
- elog(ERROR, "JOIN/USING clause must return type bool, not type %s",
- typeidTypeName(exprType(result)));
+ elog(ERROR, "JOIN/USING clause must return type boolean, not type %s",
+ format_type_be(exprType(result)));
return result;
} /* transformJoinUsingClause() */
@@ -328,8 +329,8 @@ transformJoinOnClause(ParseState *pstate, JoinExpr *j,
result = transformExpr(pstate, j->quals, EXPR_COLUMN_FIRST);
if (! coerce_to_boolean(pstate, &result))
- elog(ERROR, "JOIN/ON clause must return type bool, not type %s",
- typeidTypeName(exprType(result)));
+ elog(ERROR, "JOIN/ON clause must return type boolean, not type %s",
+ format_type_be(exprType(result)));
pstate->p_namespace = save_namespace;
@@ -775,8 +776,8 @@ transformWhereClause(ParseState *pstate, Node *clause)
qual = transformExpr(pstate, clause, EXPR_COLUMN_FIRST);
if (! coerce_to_boolean(pstate, &qual))
- elog(ERROR, "WHERE clause must return type bool, not type %s",
- typeidTypeName(exprType(qual)));
+ elog(ERROR, "WHERE clause must return type boolean, not type %s",
+ format_type_be(exprType(qual)));
return qual;
}
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 5fda57f5f92..7639fd2db5c 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.98 2001/06/19 22:39:11 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.99 2001/08/09 18:28:17 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -179,13 +179,13 @@ transformExpr(ParseState *pstate, Node *expr, int precedence)
if (! coerce_to_boolean(pstate, &lexpr))
elog(ERROR, "left-hand side of AND is type '%s', not '%s'",
- typeidTypeName(exprType(lexpr)),
- typeidTypeName(BOOLOID));
+ format_type_be(exprType(lexpr)),
+ format_type_be(BOOLOID));
if (! coerce_to_boolean(pstate, &rexpr))
elog(ERROR, "right-hand side of AND is type '%s', not '%s'",
- typeidTypeName(exprType(rexpr)),
- typeidTypeName(BOOLOID));
+ format_type_be(exprType(rexpr)),
+ format_type_be(BOOLOID));
expr->typeOid = BOOLOID;
expr->opType = AND_EXPR;
@@ -205,13 +205,13 @@ transformExpr(ParseState *pstate, Node *expr, int precedence)
if (! coerce_to_boolean(pstate, &lexpr))
elog(ERROR, "left-hand side of OR is type '%s', not '%s'",
- typeidTypeName(exprType(lexpr)),
- typeidTypeName(BOOLOID));
+ format_type_be(exprType(lexpr)),
+ format_type_be(BOOLOID));
if (! coerce_to_boolean(pstate, &rexpr))
elog(ERROR, "right-hand side of OR is type '%s', not '%s'",
- typeidTypeName(exprType(rexpr)),
- typeidTypeName(BOOLOID));
+ format_type_be(exprType(rexpr)),
+ format_type_be(BOOLOID));
expr->typeOid = BOOLOID;
expr->opType = OR_EXPR;
@@ -228,8 +228,8 @@ transformExpr(ParseState *pstate, Node *expr, int precedence)
if (! coerce_to_boolean(pstate, &rexpr))
elog(ERROR, "argument to NOT is type '%s', not '%s'",
- typeidTypeName(exprType(rexpr)),
- typeidTypeName(BOOLOID));
+ format_type_be(exprType(rexpr)),
+ format_type_be(BOOLOID));
expr->typeOid = BOOLOID;
expr->opType = NOT_EXPR;
@@ -962,8 +962,8 @@ parser_typecast_expression(ParseState *pstate,
targetType, typename->typmod);
if (expr == NULL)
elog(ERROR, "Cannot cast type '%s' to '%s'",
- typeidTypeName(inputType),
- typeidTypeName(targetType));
+ format_type_be(inputType),
+ format_type_be(targetType));
}
/*
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c
index 12013116759..f72bddfc6c7 100644
--- a/src/backend/parser/parse_func.c
+++ b/src/backend/parser/parse_func.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.109 2001/06/22 19:16:22 wieck Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.110 2001/08/09 18:28:18 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -29,6 +29,7 @@
#include "parser/parse_func.h"
#include "parser/parse_relation.h"
#include "parser/parse_type.h"
+#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
@@ -288,7 +289,7 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
{
/* Multiple possible matches --- give up */
elog(ERROR, "Unable to select an aggregate function %s(%s)",
- funcname, typeidTypeName(basetype));
+ funcname, format_type_be(basetype));
}
}
@@ -300,7 +301,7 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
* function could not have been meant.
*/
elog(ERROR, "There is no aggregate function %s(%s)",
- funcname, typeidTypeName(basetype));
+ funcname, format_type_be(basetype));
}
}
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c
index 1c9933c2f1a..8625af7b96e 100644
--- a/src/backend/parser/parse_node.c
+++ b/src/backend/parser/parse_node.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.54 2001/05/22 16:37:16 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.55 2001/08/09 18:28:18 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -373,8 +373,8 @@ transformArraySubscripts(ParseState *pstate,
elog(ERROR, "Array assignment requires type '%s'"
" but expression is of type '%s'"
"\n\tYou will need to rewrite or cast the expression",
- typeidTypeName(typeneeded),
- typeidTypeName(typesource));
+ format_type_be(typeneeded),
+ format_type_be(typesource));
}
}
}
diff --git a/src/backend/parser/parse_oper.c b/src/backend/parser/parse_oper.c
index b63c5c36a2f..8fb8856658f 100644
--- a/src/backend/parser/parse_oper.c
+++ b/src/backend/parser/parse_oper.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.49 2001/04/23 04:32:30 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.50 2001/08/09 18:28:18 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,6 +22,7 @@
#include "parser/parse_func.h"
#include "parser/parse_oper.h"
#include "parser/parse_type.h"
+#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/syscache.h"
@@ -48,7 +49,7 @@ any_ordering_op(Oid argtype)
if (!OidIsValid(order_opid))
elog(ERROR, "Unable to identify an ordering operator '%s' for type '%s'"
"\n\tUse an explicit ordering operator or modify the query",
- "<", typeidTypeName(argtype));
+ "<", format_type_be(argtype));
return order_opid;
}
@@ -931,7 +932,7 @@ op_error(char *op, Oid arg1, Oid arg2)
elog(ERROR, "Unable to identify an operator '%s' for types '%s' and '%s'"
"\n\tYou will have to retype this query using an explicit cast",
- op, typeidTypeName(arg1), typeidTypeName(arg2));
+ op, format_type_be(arg1), format_type_be(arg2));
}
/* unary_op_error()
@@ -942,13 +943,25 @@ static void
unary_op_error(char *op, Oid arg, bool is_left_op)
{
if (!typeidIsValid(arg))
- elog(ERROR, "Argument of %s operator '%s' has an unknown type"
- "\n\tProbably a bad attribute name",
- (is_left_op ? "left" : "right"),
- op);
-
- elog(ERROR, "Unable to identify a %s operator '%s' for type '%s'"
- "\n\tYou may need to add parentheses or an explicit cast",
- (is_left_op ? "left" : "right"),
- op, typeidTypeName(arg));
+ {
+ if (is_left_op)
+ elog(ERROR, "operand of prefix operator '%s' has an unknown type"
+ "\n\t(probably an invalid column reference)",
+ op);
+ else
+ elog(ERROR, "operand of postfix operator '%s' has an unknown type"
+ "\n\t(probably an invalid column reference)",
+ op);
+ }
+ else
+ {
+ if (is_left_op)
+ elog(ERROR, "Unable to identify a prefix operator '%s' for type '%s'"
+ "\n\tYou may need to add parentheses or an explicit cast",
+ op, format_type_be(arg));
+ else
+ elog(ERROR, "Unable to identify a postfix operator '%s' for type '%s'"
+ "\n\tYou may need to add parentheses or an explicit cast",
+ op, format_type_be(arg));
+ }
}
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index bc8d508b586..37abe11ef6d 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.69 2001/06/24 02:41:21 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.70 2001/08/09 18:28:18 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,6 +22,7 @@
#include "parser/parse_relation.h"
#include "parser/parse_target.h"
#include "parser/parse_type.h"
+#include "utils/builtins.h"
static List *ExpandAllTables(ParseState *pstate);
@@ -265,12 +266,12 @@ updateTargetListEntry(ParseState *pstate,
tle->expr = CoerceTargetExpr(pstate, tle->expr, type_id,
attrtype, attrtypmod);
if (tle->expr == NULL)
- elog(ERROR, "Attribute '%s' is of type '%s'"
+ 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,
- typeidTypeName(attrtype),
- typeidTypeName(type_id));
+ format_type_be(attrtype),
+ format_type_be(type_id));
}
/*
diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c
index ca46bccf5b8..3f209d63b88 100644
--- a/src/backend/utils/adt/format_type.c
+++ b/src/backend/utils/adt/format_type.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.13 2001/05/22 16:37:16 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.14 2001/08/09 18:28:18 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -27,7 +27,7 @@
#define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
-static char *format_type_internal(Oid type_oid, int32 typemod);
+static char *format_type_internal(Oid type_oid, int32 typemod, bool allow_invalid);
static char *
@@ -78,14 +78,27 @@ format_type(PG_FUNCTION_ARGS)
else
typemod = -1; /* default typmod */
- result = format_type_internal(type_oid, typemod);
+ result = format_type_internal(type_oid, typemod, true);
PG_RETURN_DATUM(_textin(result));
}
+
+/*
+ * This version is for use within the backend in error messages, etc.
+ * One difference is that it will fail for an invalid type.
+ */
+char *
+format_type_be(Oid type_oid)
+{
+ return format_type_internal(type_oid, -1, false);
+}
+
+
+
static char *
-format_type_internal(Oid type_oid, int32 typemod)
+format_type_internal(Oid type_oid, int32 typemod, bool allow_invalid)
{
bool with_typemod = (typemod >= 0);
HeapTuple tuple;
@@ -95,14 +108,19 @@ format_type_internal(Oid type_oid, int32 typemod)
char *name;
char *buf;
- if (type_oid == InvalidOid)
+ if (type_oid == InvalidOid && allow_invalid)
return pstrdup("-");
tuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(type_oid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- return pstrdup("???");
+ {
+ if (allow_invalid)
+ return pstrdup("???");
+ else
+ elog(ERROR, "could not locate data type with oid %u in catalog", type_oid);
+ }
array_base_type = ((Form_pg_type) GETSTRUCT(tuple))->typelem;
typlen = ((Form_pg_type) GETSTRUCT(tuple))->typlen;
@@ -114,7 +132,12 @@ format_type_internal(Oid type_oid, int32 typemod)
ObjectIdGetDatum(array_base_type),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- return pstrdup("???[]");
+ {
+ if (allow_invalid)
+ return pstrdup("???[]");
+ else
+ elog(ERROR, "could not locate data type with oid %u in catalog", type_oid);
+ }
is_array = true;
type_oid = array_base_type;
}
@@ -305,7 +328,7 @@ oidvectortypes(PG_FUNCTION_ARGS)
for (num = 0; num < numargs; num++)
{
- char *typename = format_type_internal(oidArray[num], -1);
+ char *typename = format_type_internal(oidArray[num], -1, true);
if (left < strlen(typename) + 2)
{