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

3683{
3684 ListCell *l;
3685
3686 foreach(l, qry->rowMarks)
3687 {
3688 RowMarkClause *rc = (RowMarkClause *) lfirst(l);
3689
3690 if (rc->rti == rtindex)
3691 return rc;
3692 }
3693 return NULL;
3694}
#define lfirst(lc)
Definition pg_list.h:172
static int fb(int x)
List * rowMarks
Definition parsenodes.h:239

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

3513{
3514 bool result;
3515
3516 switch (rte->rtekind)
3517 {
3518 case RTE_RELATION:
3519 {
3520 /*
3521 * Plain relation RTE --- get the attribute's catalog entry
3522 */
3523 HeapTuple tp;
3525
3527 ObjectIdGetDatum(rte->relid),
3529 if (!HeapTupleIsValid(tp)) /* shouldn't happen */
3530 elog(ERROR, "cache lookup failed for attribute %d of relation %u",
3531 attnum, rte->relid);
3533 result = att_tup->attisdropped;
3534 ReleaseSysCache(tp);
3535 }
3536 break;
3537 case RTE_SUBQUERY:
3538 case RTE_TABLEFUNC:
3539 case RTE_VALUES:
3540 case RTE_CTE:
3541 case RTE_GROUP:
3542 case RTE_GRAPH_TABLE:
3543
3544 /*
3545 * Subselect, Table Functions, Values, CTE, GROUP RTEs, Property
3546 * graph references never have dropped columns
3547 */
3548 result = false;
3549 break;
3551 {
3552 /* Check dropped-ness by testing for valid coltype */
3553 if (attnum <= 0 ||
3554 attnum > list_length(rte->coltypes))
3555 elog(ERROR, "invalid varattno %d", attnum);
3556 result = !OidIsValid((list_nth_oid(rte->coltypes, attnum - 1)));
3557 }
3558 break;
3559 case RTE_JOIN:
3560 {
3561 /*
3562 * A join RTE would not have dropped columns when constructed,
3563 * but one in a stored rule might contain columns that were
3564 * dropped from the underlying tables, if said columns are
3565 * nowhere explicitly referenced in the rule. This will be
3566 * signaled to us by a null pointer in the joinaliasvars list.
3567 */
3568 Var *aliasvar;
3569
3570 if (attnum <= 0 ||
3571 attnum > list_length(rte->joinaliasvars))
3572 elog(ERROR, "invalid varattno %d", attnum);
3573 aliasvar = (Var *) list_nth(rte->joinaliasvars, attnum - 1);
3574
3575 result = (aliasvar == NULL);
3576 }
3577 break;
3578 case RTE_FUNCTION:
3579 {
3580 /* Function RTE */
3581 ListCell *lc;
3582 int atts_done = 0;
3583
3584 /*
3585 * Dropped attributes are only possible with functions that
3586 * return named composite types. In such a case we have to
3587 * look up the result type to see if it currently has this
3588 * column dropped. So first, loop over the funcs until we
3589 * find the one that covers the requested column.
3590 */
3591 foreach(lc, rte->functions)
3592 {
3594
3595 if (attnum > atts_done &&
3597 {
3598 TupleDesc tupdesc;
3599
3600 /* If it has a coldeflist, it returns RECORD */
3601 if (rtfunc->funccolnames != NIL)
3602 return false; /* can't have any dropped columns */
3603
3604 tupdesc = get_expr_result_tupdesc(rtfunc->funcexpr,
3605 true);
3606 if (tupdesc)
3607 {
3608 /* Composite data type, e.g. a table's row type */
3609 CompactAttribute *att;
3610
3611 Assert(tupdesc);
3613 att = TupleDescCompactAttr(tupdesc,
3614 attnum - atts_done - 1);
3615 return att->attisdropped;
3616 }
3617 /* Otherwise, it can't have any dropped columns */
3618 return false;
3619 }
3620 atts_done += rtfunc->funccolcount;
3621 }
3622
3623 /* If we get here, must be looking for the ordinality column */
3624 if (rte->funcordinality && attnum == atts_done + 1)
3625 return false;
3626
3627 /* this probably can't happen ... */
3628 ereport(ERROR,
3630 errmsg("column %d of relation \"%s\" does not exist",
3631 attnum,
3632 rte->eref->aliasname)));
3633 result = false; /* keep compiler quiet */
3634 }
3635 break;
3636 case RTE_RESULT:
3637 /* this probably can't happen ... */
3638 ereport(ERROR,
3640 errmsg("column %d of relation \"%s\" does not exist",
3641 attnum,
3642 rte->eref->aliasname)));
3643 result = false; /* keep compiler quiet */
3644 break;
3645 default:
3646 elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind);
3647 result = false; /* keep compiler quiet */
3648 }
3649
3650 return result;
3651}
#define Assert(condition)
Definition c.h:943
#define OidIsValid(objectId)
Definition c.h:858
uint32 result
int errcode(int sqlerrcode)
Definition elog.c:875
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
TupleDesc get_expr_result_tupdesc(Node *expr, bool noError)
Definition funcapi.c:553
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
static char * errmsg
@ RTE_JOIN
@ RTE_CTE
@ RTE_NAMEDTUPLESTORE
@ RTE_VALUES
@ RTE_SUBQUERY
@ RTE_RESULT
@ RTE_FUNCTION
@ RTE_TABLEFUNC
@ RTE_GROUP
@ RTE_GRAPH_TABLE
@ 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:353
static void * list_nth(const List *list, int n)
Definition pg_list.h:331
static Datum Int16GetDatum(int16 X)
Definition postgres.h:172
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
bool attisdropped
Definition tupdesc.h:78
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Definition syscache.c:231
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:195

References Assert, CompactAttribute::attisdropped, 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(), result, RTE_CTE, RTE_FUNCTION, RTE_GRAPH_TABLE, 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 3474 of file parse_relation.c.

3475{
3477 return "*";
3478
3479 /*
3480 * If there is a user-written column alias, use it.
3481 */
3482 if (rte->alias &&
3483 attnum > 0 && attnum <= list_length(rte->alias->colnames))
3484 return strVal(list_nth(rte->alias->colnames, attnum - 1));
3485
3486 /*
3487 * If the RTE is a relation, go to the system catalogs not the
3488 * eref->colnames list. This is a little slower but it will give the
3489 * right answer if the column has been renamed since the eref list was
3490 * built (which can easily happen for rules).
3491 */
3492 if (rte->rtekind == RTE_RELATION)
3493 return get_attname(rte->relid, attnum, false);
3494
3495 /*
3496 * Otherwise use the column name from eref. There should always be one.
3497 */
3498 if (attnum > 0 && attnum <= list_length(rte->eref->colnames))
3499 return strVal(list_nth(rte->eref->colnames, attnum - 1));
3500
3501 /* else caller gave us a bogus attnum */
3502 elog(ERROR, "invalid attnum %d for rangetable entry %s",
3503 attnum, rte->eref->aliasname);
3504 return NULL; /* keep compiler quiet */
3505}
#define InvalidAttrNumber
Definition attnum.h:23
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition lsyscache.c:1045
#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()