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 */
27typedef 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
37extern RangeTblEntry *refnameRangeTblEntry(ParseState *pstate,
38 const char *schemaname,
39 const char *refname,
40 int location,
41 int *sublevels_up);
42extern CommonTableExpr *scanNameSpaceForCTE(ParseState *pstate,
43 const char *refname,
44 Index *ctelevelsup);
45extern bool scanNameSpaceForENR(ParseState *pstate, const char *refname);
46extern void checkNameSpaceConflicts(ParseState *pstate, List *namespace1,
47 List *namespace2);
48extern int RTERangeTablePosn(ParseState *pstate,
49 RangeTblEntry *rte,
50 int *sublevels_up);
51extern RangeTblEntry *GetRTEByRangeTablePosn(ParseState *pstate,
52 int varno,
53 int sublevels_up);
54extern CommonTableExpr *GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte,
55 int rtelevelsup);
56extern Node *scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte,
57 const char *colname, int location,
58 int fuzzy_rte_penalty, FuzzyAttrMatchState *fuzzystate);
59extern Node *colNameToVar(ParseState *pstate, const char *colname, bool localonly,
60 int location);
61extern void markVarForSelectPriv(ParseState *pstate, Var *var,
62 RangeTblEntry *rte);
63extern Relation parserOpenTable(ParseState *pstate, const RangeVar *relation,
64 int lockmode);
65extern RangeTblEntry *addRangeTableEntry(ParseState *pstate,
66 RangeVar *relation,
67 Alias *alias,
68 bool inh,
69 bool inFromCl);
70extern RangeTblEntry *addRangeTableEntryForRelation(ParseState *pstate,
71 Relation rel,
72 int lockmode,
73 Alias *alias,
74 bool inh,
75 bool inFromCl);
76extern RangeTblEntry *addRangeTableEntryForSubquery(ParseState *pstate,
77 Query *subquery,
78 Alias *alias,
79 bool lateral,
80 bool inFromCl);
81extern RangeTblEntry *addRangeTableEntryForFunction(ParseState *pstate,
82 List *funcnames,
83 List *funcexprs,
84 List *coldeflists,
85 RangeFunction *rangefunc,
86 bool lateral,
87 bool inFromCl);
88extern 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);
96extern RangeTblEntry *addRangeTableEntryForTableFunc(ParseState *pstate,
97 TableFunc *tf,
98 Alias *alias,
99 bool lateral,
100 bool inFromCl);
101extern RangeTblEntry *addRangeTableEntryForJoin(ParseState *pstate,
102 List *colnames,
103 JoinType jointype,
104 List *aliasvars,
105 Alias *alias,
106 bool inFromCl);
107extern RangeTblEntry *addRangeTableEntryForCTE(ParseState *pstate,
108 CommonTableExpr *cte,
109 Index levelsup,
110 RangeVar *rv,
111 bool inFromCl);
112extern RangeTblEntry *addRangeTableEntryForENR(ParseState *pstate,
113 RangeVar *rv,
114 bool inFromCl);
115extern bool isLockedRefname(ParseState *pstate, const char *refname);
116extern void addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte,
117 bool addToJoinList,
118 bool addToRelNameSpace, bool addToVarNameSpace);
119extern void errorMissingRTE(ParseState *pstate, RangeVar *relation) pg_attribute_noreturn();
120extern void errorMissingColumn(ParseState *pstate,
121 const char *relname, const char *colname, int location) pg_attribute_noreturn();
122extern void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up,
123 int location, bool include_dropped,
124 List **colnames, List **colvars);
125extern List *expandRelAttrs(ParseState *pstate, RangeTblEntry *rte,
126 int rtindex, int sublevels_up, int location);
127extern int attnameAttNum(Relation rd, const char *attname, bool sysColOK);
128extern const NameData *attnumAttName(Relation rd, int attid);
129extern Oid attnumTypeId(Relation rd, int attid);
130extern Oid attnumCollationId(Relation rd, int attid);
131extern bool isQueryUsingTempRelation(Query *query);
132
133#endif /* PARSE_RELATION_H */
134