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

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

Definition at line 31 of file parsetree.h.

Function Documentation

◆ get_parse_rowmark()

RowMarkClause* get_parse_rowmark ( Query qry,
Index  rtindex 
)

Definition at line 3459 of file parse_relation.c.

3460 {
3461  ListCell *l;
3462 
3463  foreach(l, qry->rowMarks)
3464  {
3465  RowMarkClause *rc = (RowMarkClause *) lfirst(l);
3466 
3467  if (rc->rti == rtindex)
3468  return rc;
3469  }
3470  return NULL;
3471 }
#define lfirst(lc)
Definition: pg_list.h:172
List * rowMarks
Definition: parsenodes.h:217

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

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

◆ get_rte_attribute_is_dropped()

bool get_rte_attribute_is_dropped ( RangeTblEntry rte,
AttrNumber  attnum 
)

Definition at line 3291 of file parse_relation.c.

3292 {
3293  bool result;
3294 
3295  switch (rte->rtekind)
3296  {
3297  case RTE_RELATION:
3298  {
3299  /*
3300  * Plain relation RTE --- get the attribute's catalog entry
3301  */
3302  HeapTuple tp;
3303  Form_pg_attribute att_tup;
3304 
3305  tp = SearchSysCache2(ATTNUM,
3306  ObjectIdGetDatum(rte->relid),
3308  if (!HeapTupleIsValid(tp)) /* shouldn't happen */
3309  elog(ERROR, "cache lookup failed for attribute %d of relation %u",
3310  attnum, rte->relid);
3311  att_tup = (Form_pg_attribute) GETSTRUCT(tp);
3312  result = att_tup->attisdropped;
3313  ReleaseSysCache(tp);
3314  }
3315  break;
3316  case RTE_SUBQUERY:
3317  case RTE_TABLEFUNC:
3318  case RTE_VALUES:
3319  case RTE_CTE:
3320 
3321  /*
3322  * Subselect, Table Functions, Values, CTE RTEs never have dropped
3323  * columns
3324  */
3325  result = false;
3326  break;
3327  case RTE_NAMEDTUPLESTORE:
3328  {
3329  /* Check dropped-ness by testing for valid coltype */
3330  if (attnum <= 0 ||
3331  attnum > list_length(rte->coltypes))
3332  elog(ERROR, "invalid varattno %d", attnum);
3333  result = !OidIsValid((list_nth_oid(rte->coltypes, attnum - 1)));
3334  }
3335  break;
3336  case RTE_JOIN:
3337  {
3338  /*
3339  * A join RTE would not have dropped columns when constructed,
3340  * but one in a stored rule might contain columns that were
3341  * dropped from the underlying tables, if said columns are
3342  * nowhere explicitly referenced in the rule. This will be
3343  * signaled to us by a null pointer in the joinaliasvars list.
3344  */
3345  Var *aliasvar;
3346 
3347  if (attnum <= 0 ||
3348  attnum > list_length(rte->joinaliasvars))
3349  elog(ERROR, "invalid varattno %d", attnum);
3350  aliasvar = (Var *) list_nth(rte->joinaliasvars, attnum - 1);
3351 
3352  result = (aliasvar == NULL);
3353  }
3354  break;
3355  case RTE_FUNCTION:
3356  {
3357  /* Function RTE */
3358  ListCell *lc;
3359  int atts_done = 0;
3360 
3361  /*
3362  * Dropped attributes are only possible with functions that
3363  * return named composite types. In such a case we have to
3364  * look up the result type to see if it currently has this
3365  * column dropped. So first, loop over the funcs until we
3366  * find the one that covers the requested column.
3367  */
3368  foreach(lc, rte->functions)
3369  {
3370  RangeTblFunction *rtfunc = (RangeTblFunction *) lfirst(lc);
3371 
3372  if (attnum > atts_done &&
3373  attnum <= atts_done + rtfunc->funccolcount)
3374  {
3375  TupleDesc tupdesc;
3376 
3377  /* If it has a coldeflist, it returns RECORD */
3378  if (rtfunc->funccolnames != NIL)
3379  return false; /* can't have any dropped columns */
3380 
3381  tupdesc = get_expr_result_tupdesc(rtfunc->funcexpr,
3382  true);
3383  if (tupdesc)
3384  {
3385  /* Composite data type, e.g. a table's row type */
3386  Form_pg_attribute att_tup;
3387 
3388  Assert(tupdesc);
3389  Assert(attnum - atts_done <= tupdesc->natts);
3390  att_tup = TupleDescAttr(tupdesc,
3391  attnum - atts_done - 1);
3392  return att_tup->attisdropped;
3393  }
3394  /* Otherwise, it can't have any dropped columns */
3395  return false;
3396  }
3397  atts_done += rtfunc->funccolcount;
3398  }
3399 
3400  /* If we get here, must be looking for the ordinality column */
3401  if (rte->funcordinality && attnum == atts_done + 1)
3402  return false;
3403 
3404  /* this probably can't happen ... */
3405  ereport(ERROR,
3406  (errcode(ERRCODE_UNDEFINED_COLUMN),
3407  errmsg("column %d of relation \"%s\" does not exist",
3408  attnum,
3409  rte->eref->aliasname)));
3410  result = false; /* keep compiler quiet */
3411  }
3412  break;
3413  case RTE_RESULT:
3414  /* this probably can't happen ... */
3415  ereport(ERROR,
3416  (errcode(ERRCODE_UNDEFINED_COLUMN),
3417  errmsg("column %d of relation \"%s\" does not exist",
3418  attnum,
3419  rte->eref->aliasname)));
3420  result = false; /* keep compiler quiet */
3421  break;
3422  default:
3423  elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind);
3424  result = false; /* keep compiler quiet */
3425  }
3426 
3427  return result;
3428 }
#define Assert(condition)
Definition: c.h:858
#define OidIsValid(objectId)
Definition: c.h:775
int errcode(int sqlerrcode)
Definition: elog.c:857
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define ereport(elevel,...)
Definition: elog.h:149
TupleDesc get_expr_result_tupdesc(Node *expr, bool noError)
Definition: funcapi.c:551
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
@ RTE_JOIN
Definition: parsenodes.h:1030
@ RTE_CTE
Definition: parsenodes.h:1034
@ RTE_NAMEDTUPLESTORE
Definition: parsenodes.h:1035
@ RTE_VALUES
Definition: parsenodes.h:1033
@ RTE_SUBQUERY
Definition: parsenodes.h:1029
@ RTE_RESULT
Definition: parsenodes.h:1036
@ RTE_FUNCTION
Definition: parsenodes.h:1031
@ RTE_TABLEFUNC
Definition: parsenodes.h:1032
@ RTE_RELATION
Definition: parsenodes.h:1028
int16 attnum
Definition: pg_attribute.h:74
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
static Oid list_nth_oid(const List *list, int n)
Definition: pg_list.h:321
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:172
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
bool funcordinality
Definition: parsenodes.h:1189
List * functions
Definition: parsenodes.h:1187
RTEKind rtekind
Definition: parsenodes.h:1057
Definition: primnodes.h:248
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:266
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:229
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

References Assert, attnum, elog, ereport, errcode(), errmsg(), ERROR, RangeTblFunction::funcexpr, RangeTblEntry::funcordinality, RangeTblEntry::functions, get_expr_result_tupdesc(), GETSTRUCT, HeapTupleIsValid, Int16GetDatum(), lfirst, list_length(), list_nth(), list_nth_oid(), NIL, 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().

◆ get_rte_attribute_name()

char* get_rte_attribute_name ( RangeTblEntry rte,
AttrNumber  attnum 
)

Definition at line 3253 of file parse_relation.c.

3254 {
3255  if (attnum == InvalidAttrNumber)
3256  return "*";
3257 
3258  /*
3259  * If there is a user-written column alias, use it.
3260  */
3261  if (rte->alias &&
3262  attnum > 0 && attnum <= list_length(rte->alias->colnames))
3263  return strVal(list_nth(rte->alias->colnames, attnum - 1));
3264 
3265  /*
3266  * If the RTE is a relation, go to the system catalogs not the
3267  * eref->colnames list. This is a little slower but it will give the
3268  * right answer if the column has been renamed since the eref list was
3269  * built (which can easily happen for rules).
3270  */
3271  if (rte->rtekind == RTE_RELATION)
3272  return get_attname(rte->relid, attnum, false);
3273 
3274  /*
3275  * Otherwise use the column name from eref. There should always be one.
3276  */
3277  if (attnum > 0 && attnum <= list_length(rte->eref->colnames))
3278  return strVal(list_nth(rte->eref->colnames, attnum - 1));
3279 
3280  /* else caller gave us a bogus attnum */
3281  elog(ERROR, "invalid attnum %d for rangetable entry %s",
3282  attnum, rte->eref->aliasname);
3283  return NULL; /* keep compiler quiet */
3284 }
#define InvalidAttrNumber
Definition: attnum.h:23
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:827
#define strVal(v)
Definition: value.h:82

References attnum, elog, 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().

◆ get_tle_by_resno()