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

3451 {
3452  ListCell *l;
3453 
3454  foreach(l, qry->rowMarks)
3455  {
3456  RowMarkClause *rc = (RowMarkClause *) lfirst(l);
3457 
3458  if (rc->rti == rtindex)
3459  return rc;
3460  }
3461  return NULL;
3462 }
#define lfirst(lc)
Definition: pg_list.h:172
List * rowMarks
Definition: parsenodes.h:216

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

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

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