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 3456 of file parse_relation.c.

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

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 3292 of file parse_relation.c.

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

References Alias::aliasname, Assert(), attnum, ATTNUM, RangeTblEntry::coltypes, elog(), RangeTblEntry::eref, ereport, errcode(), errmsg(), ERROR, 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().

◆ get_rte_attribute_name()

char* get_rte_attribute_name ( RangeTblEntry rte,
AttrNumber  attnum 
)

Definition at line 3254 of file parse_relation.c.

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

References RangeTblEntry::alias, Alias::aliasname, attnum, 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().

◆ get_tle_by_resno()