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

3651{
3652 ListCell *l;
3653
3654 foreach(l, qry->rowMarks)
3655 {
3656 RowMarkClause *rc = (RowMarkClause *) lfirst(l);
3657
3658 if (rc->rti == rtindex)
3659 return rc;
3660 }
3661 return NULL;
3662}
#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 3480 of file parse_relation.c.

3481{
3482 bool result;
3483
3484 switch (rte->rtekind)
3485 {
3486 case RTE_RELATION:
3487 {
3488 /*
3489 * Plain relation RTE --- get the attribute's catalog entry
3490 */
3491 HeapTuple tp;
3493
3495 ObjectIdGetDatum(rte->relid),
3497 if (!HeapTupleIsValid(tp)) /* shouldn't happen */
3498 elog(ERROR, "cache lookup failed for attribute %d of relation %u",
3499 attnum, rte->relid);
3501 result = att_tup->attisdropped;
3502 ReleaseSysCache(tp);
3503 }
3504 break;
3505 case RTE_SUBQUERY:
3506 case RTE_TABLEFUNC:
3507 case RTE_VALUES:
3508 case RTE_CTE:
3509 case RTE_GROUP:
3510 case RTE_GRAPH_TABLE:
3511
3512 /*
3513 * Subselect, Table Functions, Values, CTE, GROUP RTEs, Property
3514 * graph references never have dropped columns
3515 */
3516 result = false;
3517 break;
3519 {
3520 /* Check dropped-ness by testing for valid coltype */
3521 if (attnum <= 0 ||
3522 attnum > list_length(rte->coltypes))
3523 elog(ERROR, "invalid varattno %d", attnum);
3524 result = !OidIsValid((list_nth_oid(rte->coltypes, attnum - 1)));
3525 }
3526 break;
3527 case RTE_JOIN:
3528 {
3529 /*
3530 * A join RTE would not have dropped columns when constructed,
3531 * but one in a stored rule might contain columns that were
3532 * dropped from the underlying tables, if said columns are
3533 * nowhere explicitly referenced in the rule. This will be
3534 * signaled to us by a null pointer in the joinaliasvars list.
3535 */
3536 Var *aliasvar;
3537
3538 if (attnum <= 0 ||
3539 attnum > list_length(rte->joinaliasvars))
3540 elog(ERROR, "invalid varattno %d", attnum);
3541 aliasvar = (Var *) list_nth(rte->joinaliasvars, attnum - 1);
3542
3543 result = (aliasvar == NULL);
3544 }
3545 break;
3546 case RTE_FUNCTION:
3547 {
3548 /* Function RTE */
3549 ListCell *lc;
3550 int atts_done = 0;
3551
3552 /*
3553 * Dropped attributes are only possible with functions that
3554 * return named composite types. In such a case we have to
3555 * look up the result type to see if it currently has this
3556 * column dropped. So first, loop over the funcs until we
3557 * find the one that covers the requested column.
3558 */
3559 foreach(lc, rte->functions)
3560 {
3562
3563 if (attnum > atts_done &&
3565 {
3566 TupleDesc tupdesc;
3567
3568 /* If it has a coldeflist, it returns RECORD */
3569 if (rtfunc->funccolnames != NIL)
3570 return false; /* can't have any dropped columns */
3571
3572 tupdesc = get_expr_result_tupdesc(rtfunc->funcexpr,
3573 true);
3574 if (tupdesc)
3575 {
3576 /* Composite data type, e.g. a table's row type */
3578
3579 Assert(tupdesc);
3581 att = TupleDescCompactAttr(tupdesc,
3582 attnum - atts_done - 1);
3583 return att->attisdropped;
3584 }
3585 /* Otherwise, it can't have any dropped columns */
3586 return false;
3587 }
3588 atts_done += rtfunc->funccolcount;
3589 }
3590
3591 /* If we get here, must be looking for the ordinality column */
3592 if (rte->funcordinality && attnum == atts_done + 1)
3593 return false;
3594
3595 /* this probably can't happen ... */
3596 ereport(ERROR,
3598 errmsg("column %d of relation \"%s\" does not exist",
3599 attnum,
3600 rte->eref->aliasname)));
3601 result = false; /* keep compiler quiet */
3602 }
3603 break;
3604 case RTE_RESULT:
3605 /* this probably can't happen ... */
3606 ereport(ERROR,
3608 errmsg("column %d of relation \"%s\" does not exist",
3609 attnum,
3610 rte->eref->aliasname)));
3611 result = false; /* keep compiler quiet */
3612 break;
3613 default:
3614 elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind);
3615 result = false; /* keep compiler quiet */
3616 }
3617
3618 return result;
3619}
#define Assert(condition)
Definition c.h:945
#define OidIsValid(objectId)
Definition c.h:860
int errcode(int sqlerrcode)
Definition elog.c:874
#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: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
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, 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_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 3442 of file parse_relation.c.

3443{
3445 return "*";
3446
3447 /*
3448 * If there is a user-written column alias, use it.
3449 */
3450 if (rte->alias &&
3451 attnum > 0 && attnum <= list_length(rte->alias->colnames))
3452 return strVal(list_nth(rte->alias->colnames, attnum - 1));
3453
3454 /*
3455 * If the RTE is a relation, go to the system catalogs not the
3456 * eref->colnames list. This is a little slower but it will give the
3457 * right answer if the column has been renamed since the eref list was
3458 * built (which can easily happen for rules).
3459 */
3460 if (rte->rtekind == RTE_RELATION)
3461 return get_attname(rte->relid, attnum, false);
3462
3463 /*
3464 * Otherwise use the column name from eref. There should always be one.
3465 */
3466 if (attnum > 0 && attnum <= list_length(rte->eref->colnames))
3467 return strVal(list_nth(rte->eref->colnames, attnum - 1));
3468
3469 /* else caller gave us a bogus attnum */
3470 elog(ERROR, "invalid attnum %d for rangetable entry %s",
3471 attnum, rte->eref->aliasname);
3472 return NULL; /* keep compiler quiet */
3473}
#define InvalidAttrNumber
Definition attnum.h:23
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition lsyscache.c:946
#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()