Skip to content

Commit a8a8206

Browse files
committed
Deliver better error message when a relation name is used in an expression.
Per report from Ian Barwick.
1 parent 6c08905 commit a8a8206

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/backend/parser/parse_expr.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.137 2002/12/12 20:35:13 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.138 2002/12/27 20:06:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -934,6 +934,7 @@ exprType(Node *expr)
934934
if (!qtree || !IsA(qtree, Query))
935935
elog(ERROR, "exprType: Cannot get type for untransformed sublink");
936936
tent = (TargetEntry *) lfirst(qtree->targetList);
937+
Assert(IsA(tent, TargetEntry));
937938
type = tent->resdom->restype;
938939
}
939940
else
@@ -967,6 +968,16 @@ exprType(Node *expr)
967968
case T_ConstraintTestValue:
968969
type = ((ConstraintTestValue *) expr)->typeId;
969970
break;
971+
case T_RangeVar:
972+
/*
973+
* If someone uses a bare relation name in an expression,
974+
* we will likely first notice a problem here (see comments in
975+
* transformColumnRef()). Issue an appropriate error message.
976+
*/
977+
elog(ERROR, "Relation reference \"%s\" cannot be used in an expression",
978+
((RangeVar *) expr)->relname);
979+
type = InvalidOid; /* keep compiler quiet */
980+
break;
970981
default:
971982
elog(ERROR, "exprType: Do not know how to get type for %d node",
972983
nodeTag(expr));

0 commit comments

Comments
 (0)