PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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

charget_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

Definition at line 31 of file parsetree.h.

Function Documentation

◆ get_parse_rowmark()

RowMarkClause * get_parse_rowmark ( Query qry,
Index  rtindex 
)
extern

Definition at line 3553 of file parse_relation.c.

3554{
3555 ListCell *l;
3556
3557 foreach(l, qry->rowMarks)
3558 {
3559 RowMarkClause *rc = (RowMarkClause *) lfirst(l);
3560
3561 if (rc->rti == rtindex)
3562 return rc;
3563 }
3564 return NULL;
3565}
#define lfirst(lc)
Definition pg_list.h:172
static int fb(int x)
List * rowMarks
Definition parsenodes.h:234

References fb(), 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 
)
extern

Definition at line 3384 of file parse_relation.c.

3385{
3386 bool result;
3387
3388 switch (rte->rtekind)
3389 {
3390 case RTE_RELATION:
3391 {
3392 /*
3393 * Plain relation RTE --- get the attribute's catalog entry
3394 */
3395 HeapTuple tp;
3397
3399 ObjectIdGetDatum(rte->relid),
3401 if (!HeapTupleIsValid(tp)) /* shouldn't happen */
3402 elog(ERROR, "cache lookup failed for attribute %d of relation %u",
3403 attnum, rte->relid);
3405 result = att_tup->attisdropped;
3406 ReleaseSysCache(tp);
3407 }
3408 break;
3409 case RTE_SUBQUERY:
3410 case RTE_TABLEFUNC:
3411 case RTE_VALUES:
3412 case RTE_CTE:
3413 case RTE_GROUP:
3414
3415 /*
3416 * Subselect, Table Functions, Values, CTE, GROUP RTEs never have
3417 * dropped columns
3418 */
3419 result = false;
3420 break;
3422 {
3423 /* Check dropped-ness by testing for valid coltype */
3424 if (attnum <= 0 ||
3425 attnum > list_length(rte->coltypes))
3426 elog(ERROR, "invalid varattno %d", attnum);
3427 result = !OidIsValid((list_nth_oid(rte->coltypes, attnum - 1)));
3428 }
3429 break;
3430 case RTE_JOIN:
3431 {
3432 /*
3433 * A join RTE would not have dropped columns when constructed,
3434 * but one in a stored rule might contain columns that were
3435 * dropped from the underlying tables, if said columns are
3436 * nowhere explicitly referenced in the rule. This will be
3437 * signaled to us by a null pointer in the joinaliasvars list.
3438 */
3439 Var *aliasvar;
3440
3441 if (attnum <= 0 ||
3442 attnum > list_length(rte->joinaliasvars))
3443 elog(ERROR, "invalid varattno %d", attnum);
3444 aliasvar = (Var *) list_nth(rte->joinaliasvars, attnum - 1);
3445
3446 result = (aliasvar == NULL);
3447 }
3448 break;
3449 case RTE_FUNCTION:
3450 {
3451 /* Function RTE */
3452 ListCell *lc;
3453 int atts_done = 0;
3454
3455 /*
3456 * Dropped attributes are only possible with functions that
3457 * return named composite types. In such a case we have to
3458 * look up the result type to see if it currently has this
3459 * column dropped. So first, loop over the funcs until we
3460 * find the one that covers the requested column.
3461 */
3462 foreach(lc, rte->functions)
3463 {
3465
3466 if (attnum > atts_done &&
3468 {
3469 TupleDesc tupdesc;
3470
3471 /* If it has a coldeflist, it returns RECORD */
3472 if (rtfunc->funccolnames != NIL)
3473 return false; /* can't have any dropped columns */
3474
3475 tupdesc = get_expr_result_tupdesc(rtfunc->funcexpr,
3476 true);
3477 if (tupdesc)
3478 {
3479 /* Composite data type, e.g. a table's row type */
3481
3482 Assert(tupdesc);
3484 att = TupleDescCompactAttr(tupdesc,
3485 attnum - atts_done - 1);
3486 return att->attisdropped;
3487 }
3488 /* Otherwise, it can't have any dropped columns */
3489 return false;
3490 }
3491 atts_done += rtfunc->funccolcount;
3492 }
3493
3494 /* If we get here, must be looking for the ordinality column */
3495 if (rte->funcordinality && attnum == atts_done + 1)
3496 return false;
3497
3498 /* this probably can't happen ... */
3499 ereport(ERROR,
3501 errmsg("column %d of relation \"%s\" does not exist",
3502 attnum,
3503 rte->eref->aliasname)));
3504 result = false; /* keep compiler quiet */
3505 }
3506 break;
3507 case RTE_RESULT:
3508 /* this probably can't happen ... */
3509 ereport(ERROR,
3511 errmsg("column %d of relation \"%s\" does not exist",
3512 attnum,
3513 rte->eref->aliasname)));
3514 result = false; /* keep compiler quiet */
3515 break;
3516 default:
3517 elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind);
3518 result = false; /* keep compiler quiet */
3519 }
3520
3521 return result;
3522}
#define Assert(condition)
Definition c.h:885
#define OidIsValid(objectId)
Definition c.h:800
int errcode(int sqlerrcode)
Definition elog.c:874
int errmsg(const char *fmt,...)
Definition elog.c:1093
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
TupleDesc get_expr_result_tupdesc(Node *expr, bool noError)
Definition funcapi.c:551
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
@ RTE_JOIN
@ RTE_CTE
@ RTE_NAMEDTUPLESTORE
@ RTE_VALUES
@ RTE_SUBQUERY
@ RTE_RESULT
@ RTE_FUNCTION
@ RTE_TABLEFUNC
@ RTE_GROUP
@ RTE_RELATION
int16 attnum
FormData_pg_attribute * Form_pg_attribute
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:182
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Definition syscache.c:230
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:175

References Assert, attnum, elog, ereport, errcode(), errmsg(), ERROR, fb(), RangeTblFunction::funcexpr, get_expr_result_tupdesc(), GETSTRUCT(), HeapTupleIsValid, Int16GetDatum(), lfirst, list_length(), list_nth(), list_nth_oid(), NIL, ObjectIdGetDatum(), OidIsValid, ReleaseSysCache(), RTE_CTE, RTE_FUNCTION, RTE_GROUP, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, SearchSysCache2(), and TupleDescCompactAttr().

Referenced by AcquireRewriteLocks().

◆ get_rte_attribute_name()

char * get_rte_attribute_name ( RangeTblEntry rte,
AttrNumber  attnum 
)
extern

Definition at line 3346 of file parse_relation.c.

3347{
3349 return "*";
3350
3351 /*
3352 * If there is a user-written column alias, use it.
3353 */
3354 if (rte->alias &&
3355 attnum > 0 && attnum <= list_length(rte->alias->colnames))
3356 return strVal(list_nth(rte->alias->colnames, attnum - 1));
3357
3358 /*
3359 * If the RTE is a relation, go to the system catalogs not the
3360 * eref->colnames list. This is a little slower but it will give the
3361 * right answer if the column has been renamed since the eref list was
3362 * built (which can easily happen for rules).
3363 */
3364 if (rte->rtekind == RTE_RELATION)
3365 return get_attname(rte->relid, attnum, false);
3366
3367 /*
3368 * Otherwise use the column name from eref. There should always be one.
3369 */
3370 if (attnum > 0 && attnum <= list_length(rte->eref->colnames))
3371 return strVal(list_nth(rte->eref->colnames, attnum - 1));
3372
3373 /* else caller gave us a bogus attnum */
3374 elog(ERROR, "invalid attnum %d for rangetable entry %s",
3375 attnum, rte->eref->aliasname);
3376 return NULL; /* keep compiler quiet */
3377}
#define InvalidAttrNumber
Definition attnum.h:23
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition lsyscache.c:903
#define strVal(v)
Definition value.h:82

References attnum, elog, ERROR, fb(), get_attname(), InvalidAttrNumber, list_length(), list_nth(), RTE_RELATION, and strVal.

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

◆ get_tle_by_resno()