PostgreSQL Source Code  git master
parsetree.h File Reference
#include "nodes/parsenodes.h"
Include dependency graph for parsetree.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define rt_fetch(rangetable_index, rangetable)   ((RangeTblEntry *) list_nth(rangetable, (rangetable_index)-1))
 

Functions

char * get_rte_attribute_name (RangeTblEntry *rte, AttrNumber attnum)
 
bool get_rte_attribute_is_dropped (RangeTblEntry *rte, AttrNumber attnum)
 
TargetEntryget_tle_by_resno (List *tlist, AttrNumber resno)
 
RowMarkClauseget_parse_rowmark (Query *qry, Index rtindex)
 

Macro Definition Documentation

◆ rt_fetch

Function Documentation

◆ get_parse_rowmark()

RowMarkClause* get_parse_rowmark ( Query qry,
Index  rtindex 
)

Definition at line 3303 of file parse_relation.c.

References lfirst, Query::rowMarks, and RowMarkClause::rti.

Referenced by AcquireRewriteLocks(), applyLockingClause(), and ApplyRetrieveRule().

3304 {
3305  ListCell *l;
3306 
3307  foreach(l, qry->rowMarks)
3308  {
3309  RowMarkClause *rc = (RowMarkClause *) lfirst(l);
3310 
3311  if (rc->rti == rtindex)
3312  return rc;
3313  }
3314  return NULL;
3315 }
List * rowMarks
Definition: parsenodes.h:164
#define lfirst(lc)
Definition: pg_list.h:169

◆ get_rte_attribute_is_dropped()

bool get_rte_attribute_is_dropped ( RangeTblEntry rte,
AttrNumber  attnum 
)

Definition at line 3139 of file parse_relation.c.

References Alias::aliasname, Assert, ATTNUM, RangeTblEntry::coltypes, elog, RangeTblEntry::eref, ereport, errcode(), errmsg(), ERROR, RangeTblFunction::funccolcount, RangeTblFunction::funcexpr, RangeTblEntry::funcordinality, RangeTblEntry::functions, get_expr_result_tupdesc(), GETSTRUCT, HeapTupleIsValid, Int16GetDatum, RangeTblEntry::joinaliasvars, lfirst, list_length(), list_nth(), list_nth_oid(), ObjectIdGetDatum, OidIsValid, ReleaseSysCache(), RangeTblEntry::relid, RTE_CTE, RTE_FUNCTION, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, SearchSysCache2(), and TupleDescAttr.

Referenced by AcquireRewriteLocks().

3140 {
3141  bool result;
3142 
3143  switch (rte->rtekind)
3144  {
3145  case RTE_RELATION:
3146  {
3147  /*
3148  * Plain relation RTE --- get the attribute's catalog entry
3149  */
3150  HeapTuple tp;
3151  Form_pg_attribute att_tup;
3152 
3153  tp = SearchSysCache2(ATTNUM,
3154  ObjectIdGetDatum(rte->relid),
3156  if (!HeapTupleIsValid(tp)) /* shouldn't happen */
3157  elog(ERROR, "cache lookup failed for attribute %d of relation %u",
3158  attnum, rte->relid);
3159  att_tup = (Form_pg_attribute) GETSTRUCT(tp);
3160  result = att_tup->attisdropped;
3161  ReleaseSysCache(tp);
3162  }
3163  break;
3164  case RTE_SUBQUERY:
3165  case RTE_TABLEFUNC:
3166  case RTE_VALUES:
3167  case RTE_CTE:
3168 
3169  /*
3170  * Subselect, Table Functions, Values, CTE RTEs never have dropped
3171  * columns
3172  */
3173  result = false;
3174  break;
3175  case RTE_NAMEDTUPLESTORE:
3176  {
3177  /* Check dropped-ness by testing for valid coltype */
3178  if (attnum <= 0 ||
3179  attnum > list_length(rte->coltypes))
3180  elog(ERROR, "invalid varattno %d", attnum);
3181  result = !OidIsValid((list_nth_oid(rte->coltypes, attnum - 1)));
3182  }
3183  break;
3184  case RTE_JOIN:
3185  {
3186  /*
3187  * A join RTE would not have dropped columns when constructed,
3188  * but one in a stored rule might contain columns that were
3189  * dropped from the underlying tables, if said columns are
3190  * nowhere explicitly referenced in the rule. This will be
3191  * signaled to us by a null pointer in the joinaliasvars list.
3192  */
3193  Var *aliasvar;
3194 
3195  if (attnum <= 0 ||
3197  elog(ERROR, "invalid varattno %d", attnum);
3198  aliasvar = (Var *) list_nth(rte->joinaliasvars, attnum - 1);
3199 
3200  result = (aliasvar == NULL);
3201  }
3202  break;
3203  case RTE_FUNCTION:
3204  {
3205  /* Function RTE */
3206  ListCell *lc;
3207  int atts_done = 0;
3208 
3209  /*
3210  * Dropped attributes are only possible with functions that
3211  * return named composite types. In such a case we have to
3212  * look up the result type to see if it currently has this
3213  * column dropped. So first, loop over the funcs until we
3214  * find the one that covers the requested column.
3215  */
3216  foreach(lc, rte->functions)
3217  {
3218  RangeTblFunction *rtfunc = (RangeTblFunction *) lfirst(lc);
3219 
3220  if (attnum > atts_done &&
3221  attnum <= atts_done + rtfunc->funccolcount)
3222  {
3223  TupleDesc tupdesc;
3224 
3225  tupdesc = get_expr_result_tupdesc(rtfunc->funcexpr,
3226  true);
3227  if (tupdesc)
3228  {
3229  /* Composite data type, e.g. a table's row type */
3230  Form_pg_attribute att_tup;
3231 
3232  Assert(tupdesc);
3233  Assert(attnum - atts_done <= tupdesc->natts);
3234  att_tup = TupleDescAttr(tupdesc,
3235  attnum - atts_done - 1);
3236  return att_tup->attisdropped;
3237  }
3238  /* Otherwise, it can't have any dropped columns */
3239  return false;
3240  }
3241  atts_done += rtfunc->funccolcount;
3242  }
3243 
3244  /* If we get here, must be looking for the ordinality column */
3245  if (rte->funcordinality && attnum == atts_done + 1)
3246  return false;
3247 
3248  /* this probably can't happen ... */
3249  ereport(ERROR,
3250  (errcode(ERRCODE_UNDEFINED_COLUMN),
3251  errmsg("column %d of relation \"%s\" does not exist",
3252  attnum,
3253  rte->eref->aliasname)));
3254  result = false; /* keep compiler quiet */
3255  }
3256  break;
3257  case RTE_RESULT:
3258  /* this probably can't happen ... */
3259  ereport(ERROR,
3260  (errcode(ERRCODE_UNDEFINED_COLUMN),
3261  errmsg("column %d of relation \"%s\" does not exist",
3262  attnum,
3263  rte->eref->aliasname)));
3264  result = false; /* keep compiler quiet */
3265  break;
3266  default:
3267  elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind);
3268  result = false; /* keep compiler quiet */
3269  }
3270 
3271  return result;
3272 }
List * joinaliasvars
Definition: parsenodes.h:1052
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define Int16GetDatum(X)
Definition: postgres.h:451
int errcode(int sqlerrcode)
Definition: elog.c:610
bool funcordinality
Definition: parsenodes.h:1065
Definition: primnodes.h:181
#define OidIsValid(objectId)
Definition: c.h:652
static Oid list_nth_oid(const List *list, int n)
Definition: pg_list.h:288
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
TupleDesc get_expr_result_tupdesc(Node *expr, bool noError)
Definition: funcapi.c:438
static void * list_nth(const List *list, int n)
Definition: pg_list.h:266
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
int16 attnum
Definition: pg_attribute.h:79
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:746
#define lfirst(lc)
Definition: pg_list.h:169
char * aliasname
Definition: primnodes.h:42
List * functions
Definition: parsenodes.h:1064
static int list_length(const List *l)
Definition: pg_list.h:149
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1127
RTEKind rtekind
Definition: parsenodes.h:977
int errmsg(const char *fmt,...)
Definition: elog.c:821
#define elog(elevel,...)
Definition: elog.h:214
Alias * eref
Definition: parsenodes.h:1116
List * coltypes
Definition: parsenodes.h:1102

◆ get_rte_attribute_name()

char* get_rte_attribute_name ( RangeTblEntry rte,
AttrNumber  attnum 
)

Definition at line 3101 of file parse_relation.c.

References RangeTblEntry::alias, Alias::aliasname, Alias::colnames, elog, RangeTblEntry::eref, ERROR, get_attname(), InvalidAttrNumber, list_length(), list_nth(), RangeTblEntry::relid, RTE_RELATION, RangeTblEntry::rtekind, and strVal.

Referenced by check_ungrouped_columns_walker(), get_name_for_var_field(), get_variable(), and print_expr().

3102 {
3103  if (attnum == InvalidAttrNumber)
3104  return "*";
3105 
3106  /*
3107  * If there is a user-written column alias, use it.
3108  */
3109  if (rte->alias &&
3110  attnum > 0 && attnum <= list_length(rte->alias->colnames))
3111  return strVal(list_nth(rte->alias->colnames, attnum - 1));
3112 
3113  /*
3114  * If the RTE is a relation, go to the system catalogs not the
3115  * eref->colnames list. This is a little slower but it will give the
3116  * right answer if the column has been renamed since the eref list was
3117  * built (which can easily happen for rules).
3118  */
3119  if (rte->rtekind == RTE_RELATION)
3120  return get_attname(rte->relid, attnum, false);
3121 
3122  /*
3123  * Otherwise use the column name from eref. There should always be one.
3124  */
3125  if (attnum > 0 && attnum <= list_length(rte->eref->colnames))
3126  return strVal(list_nth(rte->eref->colnames, attnum - 1));
3127 
3128  /* else caller gave us a bogus attnum */
3129  elog(ERROR, "invalid attnum %d for rangetable entry %s",
3130  attnum, rte->eref->aliasname);
3131  return NULL; /* keep compiler quiet */
3132 }
Alias * alias
Definition: parsenodes.h:1115
List * colnames
Definition: primnodes.h:43
#define strVal(v)
Definition: value.h:54
#define ERROR
Definition: elog.h:43
static void * list_nth(const List *list, int n)
Definition: pg_list.h:266
int16 attnum
Definition: pg_attribute.h:79
char * aliasname
Definition: primnodes.h:42
static int list_length(const List *l)
Definition: pg_list.h:149
#define InvalidAttrNumber
Definition: attnum.h:23
RTEKind rtekind
Definition: parsenodes.h:977
#define elog(elevel,...)
Definition: elog.h:214
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:825
Alias * eref
Definition: parsenodes.h:1116

◆ get_tle_by_resno()