* parse trees.
*
*
- * Copyright (c) 1994, Regents of the University of California
+ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: parsetree.h,v 1.6 1999/02/13 23:21:57 momjian Exp $
+ * $Id: parsetree.h,v 1.21 2003/08/04 02:40:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PARSETREE_H
-#define PARSETREE_H /* include once only */
+#define PARSETREE_H
+
+#include "nodes/parsenodes.h"
+#include "nodes/pg_list.h" /* for nth(), etc */
-/* ----------------
- * need pg_list.h for definitions of CAR(), etc. macros
- * ----------------
- */
/* ----------------
* range table macros
- *
- * parse tree:
- * (root targetlist qual)
- * ^^^^
- * parse root:
- * (numlevels cmdtype resrel rangetable priority ruleinfo nestdotinfo)
- * ^^^^^^^^^^
- * range table:
- * (rtentry ...)
- * rtentry:
* ----------------
*/
-#define rt_relname(rt_entry) \
- ((!strcmp(((rt_entry)->refname),"*CURRENT*") ||\
- !strcmp(((rt_entry)->refname),"*NEW*")) ? ((rt_entry)->refname) : \
- ((char *)(rt_entry)->relname))
-
/*
* rt_fetch
- * rt_store
- *
- * Access and (destructively) replace rangetable entries.
*
+ * NB: this will crash and burn if handed an out-of-range RT index
*/
#define rt_fetch(rangetable_index, rangetable) \
- ((RangeTblEntry*)nth((rangetable_index)-1, rangetable))
-
-#define rt_store(rangetable_index, rangetable, rt) \
- set_nth(rangetable, (rangetable_index)-1, rt)
+ ((RangeTblEntry *) nth((rangetable_index)-1, rangetable))
/*
* getrelid
- * getrelname
*
* Given the range index of a relation, return the corresponding
- * relation id or relation name.
+ * relation OID. Note that InvalidOid will be returned if the
+ * RTE is for a non-relation-type RTE.
*/
#define getrelid(rangeindex,rangetable) \
- ((RangeTblEntry*)nth((rangeindex)-1, rangetable))->relid
+ (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);
-#define getrelname(rangeindex, rangetable) \
- rt_relname((RangeTblEntry*)nth((rangeindex)-1, rangetable))
+/*
+ * Given an RTE and an attribute number, return the appropriate
+ * type and typemod info for that attribute of that RTE.
+ */
+extern void get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
+ Oid *vartype, int32 *vartypmod);
-#endif /* PARSETREE_H */
+#endif /* PARSETREE_H */