*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.40 2000/09/12 21:06:49 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.41 2000/09/25 18:14:55 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
break;
default:
{
- RangeTblEntry *rt;
+ RangeTblEntry *rte;
- rt = rt_fetch(var->varno, rtable);
- relname = rt->eref->relname;
- attname = get_attname(rt->relid, var->varattno);
+ Assert(var->varno > 0 &&
+ (int) var->varno <= length(rtable));
+ rte = rt_fetch(var->varno, rtable);
+ relname = rte->eref->relname;
+ attname = get_rte_attribute_name(rte, var->varattno);
}
break;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.74 2000/09/12 21:06:58 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.75 2000/09/25 18:14:55 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
char *attname;
Assert(var->varno > 0 &&
- var->varno <= length(context->rtable));
+ (int) var->varno <= length(context->rtable));
rte = rt_fetch(var->varno, context->rtable);
- attname = get_attname(rte->relid, var->varattno);
- if (!attname)
- elog(ERROR, "cache lookup of attribute %d in relation %u failed",
- var->varattno, rte->relid);
+ attname = get_rte_attribute_name(rte, var->varattno);
elog(ERROR, "Sub-SELECT uses un-GROUPed attribute %s.%s from outer query",
rte->eref->relname, attname);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.40 2000/09/12 21:07:02 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.41 2000/09/25 18:14:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Assert(var->varno > 0 &&
(int) var->varno <= length(context->pstate->p_rtable));
rte = rt_fetch(var->varno, context->pstate->p_rtable);
- attname = get_attname(rte->relid, var->varattno);
- if (!attname)
- elog(ERROR, "cache lookup of attribute %d in relation %u failed",
- var->varattno, rte->relid);
+ attname = get_rte_attribute_name(rte, var->varattno);
elog(ERROR, "Attribute %s.%s must be GROUPed or used in an aggregate function",
rte->eref->relname, attname);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.47 2000/09/12 21:07:02 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.48 2000/09/25 18:14:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
return te_list;
}
+/* ----------
+ * get_rte_attribute_name
+ * Get an attribute name from a RangeTblEntry
+ *
+ * This is unlike get_attname() because we use aliases if available.
+ * In particular, it will work on an RTE for a subselect, whereas
+ * get_attname() only works on real relations.
+ * ----------
+ */
+char *
+get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
+{
+ char *attname;
+
+ /*
+ * If there is an alias, use it
+ */
+ if (attnum > 0 && attnum <= length(rte->eref->attrs))
+ return strVal(nth(attnum-1, rte->eref->attrs));
+ /*
+ * Can get here for a system attribute (which never has an alias),
+ * or if alias name list is too short (which probably can't happen
+ * anymore). Neither of these cases is valid for a subselect RTE.
+ */
+ if (rte->relid == InvalidOid)
+ elog(ERROR, "Invalid attnum %d for rangetable entry %s",
+ attnum, rte->eref->relname);
+ /*
+ * Use the real name of the table's column
+ */
+ attname = get_attname(rte->relid, attnum);
+ if (attname == NULL)
+ elog(ERROR, "cache lookup of attribute %d in relation %u failed",
+ attnum, rte->relid);
+ return attname;
+}
+
/*
* given relation and att name, return id of variable
*
* back to source text
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.62 2000/09/18 20:14:23 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.63 2000/09/25 18:14:54 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
static char *quote_identifier(char *ident);
static char *get_relation_name(Oid relid);
static char *get_relid_attribute_name(Oid relid, AttrNumber attnum);
-static char *get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum);
#define only_marker(rte) ((rte)->inh ? "" : "ONLY ")
attnum, relid);
return attname;
}
-
-/* ----------
- * get_rte_attribute_name
- * Get an attribute name from a RangeTblEntry
- *
- * This is unlike get_relid_attribute_name() because we use aliases if
- * available.
- * ----------
- */
-static char *
-get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
-{
- /*
- * If there is an alias, use it
- */
- if (attnum > 0 && attnum <= length(rte->eref->attrs))
- return strVal(nth(attnum-1, rte->eref->attrs));
- /*
- * Can get here for a system attribute (which never has an alias),
- * or if alias name list is too short (which probably can't happen
- * anymore). Neither of these cases is valid for a subselect RTE.
- */
- if (rte->relid == InvalidOid)
- elog(ERROR, "Invalid attnum %d for rangetable entry %s",
- attnum, rte->eref->relname);
- /*
- * Use the real name of the table's column
- */
- return get_relid_attribute_name(rte->relid, attnum);
-}
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: parsetree.h,v 1.11 2000/09/12 21:07:12 tgl Exp $
+ * $Id: parsetree.h,v 1.12 2000/09/25 18:14:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#define PARSETREE_H
#include "nodes/parsenodes.h"
-#include "nodes/pg_list.h"
+#include "nodes/pg_list.h" /* for nth(), etc */
-/* ----------------
- * need pg_list.h for definitions of nth(), etc.
- * ----------------
- */
/* ----------------
* range table macros
* rt_store
*
* Access and (destructively) replace rangetable entries.
- *
*/
#define rt_fetch(rangetable_index, rangetable) \
- ((RangeTblEntry*) nth((rangetable_index)-1, rangetable))
+ ((RangeTblEntry *) nth((rangetable_index)-1, rangetable))
#define rt_store(rangetable_index, rangetable, rt) \
set_nth(rangetable, (rangetable_index)-1, rt)
* getrelid
*
* Given the range index of a relation, return the corresponding
- * relation OID.
+ * relation OID. Note that InvalidOid will be returned if the
+ * RTE is for a sub-select rather than a relation.
*/
#define getrelid(rangeindex,rangetable) \
(rt_fetch(rangeindex, rangetable)->relid)
+/*
+ * Given an RTE and an attribute number, return the appropriate
+ * variable name or alias for that attribute of that RTE.
+ */
+extern char *get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum);
+
#endif /* PARSETREE_H */