1 | /*------------------------------------------------------------------------- |
2 | * |
3 | * parse_relation.h |
4 | * prototypes for parse_relation.c. |
5 | * |
6 | * |
7 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
8 | * Portions Copyright (c) 1994, Regents of the University of California |
9 | * |
10 | * src/include/parser/parse_relation.h |
11 | * |
12 | *------------------------------------------------------------------------- |
13 | */ |
14 | #ifndef PARSE_RELATION_H |
15 | #define PARSE_RELATION_H |
16 | |
17 | #include "parser/parse_node.h" |
18 | |
19 | |
20 | /* |
21 | * Support for fuzzily matching column. |
22 | * |
23 | * This is for building diagnostic messages, where non-exact matching |
24 | * attributes are suggested to the user. The struct's fields may be facets of |
25 | * a particular RTE, or of an entire range table, depending on context. |
26 | */ |
27 | typedef struct |
28 | { |
29 | int distance; /* Weighted distance (lowest so far) */ |
30 | RangeTblEntry *rfirst; /* RTE of first */ |
31 | AttrNumber first; /* Closest attribute so far */ |
32 | RangeTblEntry *rsecond; /* RTE of second */ |
33 | AttrNumber second; /* Second closest attribute so far */ |
34 | } FuzzyAttrMatchState; |
35 | |
36 | |
37 | extern RangeTblEntry *refnameRangeTblEntry(ParseState *pstate, |
38 | const char *schemaname, |
39 | const char *refname, |
40 | int location, |
41 | int *sublevels_up); |
42 | extern CommonTableExpr *scanNameSpaceForCTE(ParseState *pstate, |
43 | const char *refname, |
44 | Index *ctelevelsup); |
45 | extern bool scanNameSpaceForENR(ParseState *pstate, const char *refname); |
46 | extern void checkNameSpaceConflicts(ParseState *pstate, List *namespace1, |
47 | List *namespace2); |
48 | extern int RTERangeTablePosn(ParseState *pstate, |
49 | RangeTblEntry *rte, |
50 | int *sublevels_up); |
51 | extern RangeTblEntry *GetRTEByRangeTablePosn(ParseState *pstate, |
52 | int varno, |
53 | int sublevels_up); |
54 | extern CommonTableExpr *GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte, |
55 | int rtelevelsup); |
56 | extern Node *scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, |
57 | const char *colname, int location, |
58 | int fuzzy_rte_penalty, FuzzyAttrMatchState *fuzzystate); |
59 | extern Node *colNameToVar(ParseState *pstate, const char *colname, bool localonly, |
60 | int location); |
61 | extern void markVarForSelectPriv(ParseState *pstate, Var *var, |
62 | RangeTblEntry *rte); |
63 | extern Relation parserOpenTable(ParseState *pstate, const RangeVar *relation, |
64 | int lockmode); |
65 | extern RangeTblEntry *addRangeTableEntry(ParseState *pstate, |
66 | RangeVar *relation, |
67 | Alias *alias, |
68 | bool inh, |
69 | bool inFromCl); |
70 | extern RangeTblEntry *addRangeTableEntryForRelation(ParseState *pstate, |
71 | Relation rel, |
72 | int lockmode, |
73 | Alias *alias, |
74 | bool inh, |
75 | bool inFromCl); |
76 | extern RangeTblEntry *addRangeTableEntryForSubquery(ParseState *pstate, |
77 | Query *subquery, |
78 | Alias *alias, |
79 | bool lateral, |
80 | bool inFromCl); |
81 | extern RangeTblEntry *addRangeTableEntryForFunction(ParseState *pstate, |
82 | List *funcnames, |
83 | List *funcexprs, |
84 | List *coldeflists, |
85 | RangeFunction *rangefunc, |
86 | bool lateral, |
87 | bool inFromCl); |
88 | extern RangeTblEntry *addRangeTableEntryForValues(ParseState *pstate, |
89 | List *exprs, |
90 | List *coltypes, |
91 | List *coltypmods, |
92 | List *colcollations, |
93 | Alias *alias, |
94 | bool lateral, |
95 | bool inFromCl); |
96 | extern RangeTblEntry *addRangeTableEntryForTableFunc(ParseState *pstate, |
97 | TableFunc *tf, |
98 | Alias *alias, |
99 | bool lateral, |
100 | bool inFromCl); |
101 | extern RangeTblEntry *addRangeTableEntryForJoin(ParseState *pstate, |
102 | List *colnames, |
103 | JoinType jointype, |
104 | List *aliasvars, |
105 | Alias *alias, |
106 | bool inFromCl); |
107 | extern RangeTblEntry *addRangeTableEntryForCTE(ParseState *pstate, |
108 | CommonTableExpr *cte, |
109 | Index levelsup, |
110 | RangeVar *rv, |
111 | bool inFromCl); |
112 | extern RangeTblEntry *addRangeTableEntryForENR(ParseState *pstate, |
113 | RangeVar *rv, |
114 | bool inFromCl); |
115 | extern bool isLockedRefname(ParseState *pstate, const char *refname); |
116 | extern void addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte, |
117 | bool addToJoinList, |
118 | bool addToRelNameSpace, bool addToVarNameSpace); |
119 | extern void errorMissingRTE(ParseState *pstate, RangeVar *relation) pg_attribute_noreturn(); |
120 | extern void errorMissingColumn(ParseState *pstate, |
121 | const char *relname, const char *colname, int location) pg_attribute_noreturn(); |
122 | extern void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, |
123 | int location, bool include_dropped, |
124 | List **colnames, List **colvars); |
125 | extern List *expandRelAttrs(ParseState *pstate, RangeTblEntry *rte, |
126 | int rtindex, int sublevels_up, int location); |
127 | extern int attnameAttNum(Relation rd, const char *attname, bool sysColOK); |
128 | extern const NameData *attnumAttName(Relation rd, int attid); |
129 | extern Oid attnumTypeId(Relation rd, int attid); |
130 | extern Oid attnumCollationId(Relation rd, int attid); |
131 | extern bool isQueryUsingTempRelation(Query *query); |
132 | |
133 | #endif /* PARSE_RELATION_H */ |
134 | |