75 #define MAX_FUZZY_DISTANCE 3
87 const char *colname,
int location,
88 int fuzzy_rte_penalty,
93 int rtindex,
int sublevels_up,
94 int location,
bool include_dropped,
97 int count,
int offset,
98 int rtindex,
int sublevels_up,
99 int location,
bool include_dropped,
130 const char *schemaname,
140 if (schemaname != NULL)
160 while (pstate != NULL)
220 (
errcode(ERRCODE_AMBIGUOUS_ALIAS),
221 errmsg(
"table reference \"%s\" is ambiguous",
259 rte->
relid == relid &&
264 (
errcode(ERRCODE_AMBIGUOUS_ALIAS),
265 errmsg(
"table reference %u is ambiguous",
297 if (strcmp(cte->
ctename, refname) == 0)
299 *ctelevelsup = levelsup;
323 if (strcmp(cte->
ctename, refname) == 0)
358 const char *refname = relation->
relname;
362 Index ctelevelsup = 0;
405 strcmp(rte->
ctename, refname) == 0)
409 strcmp(rte->
enrname, refname) == 0)
411 if (strcmp(rte->eref->aliasname, refname) == 0)
439 foreach(l1, namespace1)
449 foreach(l2, namespace2)
457 if (strcmp(aliasname2, aliasname1) != 0)
464 (
errcode(ERRCODE_DUPLICATE_ALIAS),
465 errmsg(
"table name \"%s\" specified more than once",
493 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
494 errmsg(
"invalid reference to FROM-clause entry for table \"%s\"",
498 errhint(
"There is an entry for table \"%s\", but it cannot be referenced from this part of the query.",
500 errdetail(
"The combining JOIN type must be INNER or LEFT for a LATERAL reference."),
516 while (sublevels_up-- > 0)
528 elog(
ERROR,
"nsitem not found (internal error)");
541 while (sublevels_up-- > 0)
564 while (levelsup-- > 0)
589 const char *actual,
const char *match,
int attnum)
595 if (fuzzy_rte_penalty > fuzzystate->
distance)
602 if (actual[0] ==
'\0')
606 matchlen = strlen(match);
618 if (columndistance > matchlen / 2)
625 columndistance += fuzzy_rte_penalty;
631 if (columndistance < fuzzystate->distance)
634 fuzzystate->
distance = columndistance;
639 else if (columndistance == fuzzystate->
distance)
642 if (fuzzystate->
rsecond != NULL)
651 fuzzystate->
rfirst = NULL;
654 else if (fuzzystate->
rfirst != NULL)
681 int sublevels_up,
const char *colname,
int location)
702 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
703 errmsg(
"system column \"%s\" reference in check constraint is invalid",
711 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
712 errmsg(
"cannot use system column \"%s\" in column generation expression",
722 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
723 errmsg(
"cannot use system column \"%s\" in MERGE WHEN condition",
736 (
errcode(ERRCODE_UNDEFINED_COLUMN),
737 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
761 sysatt->attcollation,
802 const char *colname,
int location,
803 int fuzzy_rte_penalty,
828 if (strcmp(attcolname, colname) == 0)
832 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
833 errmsg(
"column reference \"%s\" is ambiguous",
840 if (fuzzystate != NULL)
842 rte, attcolname, colname,
attnum);
858 rte->relkind != RELKIND_COMPOSITE_TYPE)
887 int sublevels_up = 0;
890 while (pstate != NULL)
914 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
915 errmsg(
"column reference \"%s\" is ambiguous",
923 if (result != NULL || localonly)
959 fuzzystate->
rfirst = NULL;
964 while (pstate != NULL)
971 int fuzzy_rte_penalty = 0;
992 rte->eref->aliasname,
993 strlen(rte->eref->aliasname),
1006 fuzzy_rte_penalty, fuzzystate);
1009 if (fuzzystate->
rexact1 == NULL)
1037 int rtindex = var->
varno;
1055 var->varnullingrels =
bms_union(var->varnullingrels, relids);
1097 elog(
ERROR,
"could not find JoinExpr for whole-row reference");
1108 int varno = ((
JoinExpr *)
j->larg)->rtindex;
1113 elog(
ERROR,
"unrecognized node type: %d",
1123 int varno = ((
JoinExpr *)
j->rarg)->rtindex;
1128 elog(
ERROR,
"unrecognized node type: %d",
1179 int maxattrs = tupdesc->
natts;
1203 for (varattno = 0; varattno < maxattrs; varattno++)
1208 if (attr->attisdropped)
1220 aliaslc =
lnext(aliaslist, aliaslc);
1235 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
1236 errmsg(
"table \"%s\" has %d columns available but %d columns specified",
1237 eref->
aliasname, maxattrs - numdropped, numaliases)));
1255 Alias *alias,
int nfuncs)
1275 if (nfuncs == 1 && alias)
1300 int maxattrs = tupdesc->
natts;
1310 for (varattno = 0; varattno < maxattrs; varattno++)
1315 if (attr->attisdropped)
1318 nscolumns[varattno].
p_varno = rtindex;
1319 nscolumns[varattno].
p_varattno = varattno + 1;
1320 nscolumns[varattno].
p_vartype = attr->atttypid;
1321 nscolumns[varattno].
p_vartypmod = attr->atttypmod;
1322 nscolumns[varattno].
p_varcollid = attr->attcollation;
1330 nsitem->
p_rte = rte;
1380 nscolumns[varattno].
p_varno = rtindex;
1381 nscolumns[varattno].
p_varattno = varattno + 1;
1393 nsitem->
p_rte = rte;
1430 errmsg(
"relation \"%s.%s\" does not exist",
1443 errmsg(
"relation \"%s\" does not exist",
1445 errdetail(
"There is a WITH item named \"%s\", but it cannot be referenced from this part of the query.",
1447 errhint(
"Use WITH RECURSIVE, or re-order the WITH items to remove forward references.")));
1451 errmsg(
"relation \"%s\" does not exist",
1504 rte->relkind = rel->
rd_rel->relkind;
1505 rte->rellockmode = lockmode;
1520 rte->lateral =
false;
1521 rte->inFromCl = inFromCl;
1589 rte->relkind = rel->
rd_rel->relkind;
1590 rte->rellockmode = lockmode;
1605 rte->lateral =
false;
1606 rte->inFromCl = inFromCl;
1664 coltypes = coltypmods = colcollations =
NIL;
1674 if (varattno > numaliases)
1678 attrname =
pstrdup(te->resname);
1688 if (varattno < numaliases)
1690 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
1691 errmsg(
"table \"%s\" has %d columns available but %d columns specified",
1692 eref->
aliasname, varattno, numaliases)));
1702 rte->lateral = lateral;
1703 rte->inFromCl = inFromCl;
1717 coltypes, coltypmods, colcollations);
1785 forthree(lc1, funcexprs, lc2, funcnames, lc3, coldeflists)
1796 rtfunc->funccolnames =
NIL;
1797 rtfunc->funccoltypes =
NIL;
1798 rtfunc->funccoltypmods =
NIL;
1799 rtfunc->funccolcollations =
NIL;
1800 rtfunc->funcparams = NULL;
1815 if (coldeflist !=
NIL)
1817 switch (functypclass)
1830 if (
exprType(funcexpr) == RECORDOID)
1832 (
errcode(ERRCODE_SYNTAX_ERROR),
1833 errmsg(
"a column definition list is redundant for a function with OUT parameters"),
1838 (
errcode(ERRCODE_SYNTAX_ERROR),
1839 errmsg(
"a column definition list is redundant for a function returning a named composite type"),
1845 (
errcode(ERRCODE_SYNTAX_ERROR),
1846 errmsg(
"a column definition list is only allowed for functions returning \"record\""),
1856 (
errcode(ERRCODE_SYNTAX_ERROR),
1857 errmsg(
"a column definition list is required for functions returning \"record\""),
1893 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1894 errmsg(
"column definition lists can have at most %d entries",
1900 foreach(col, coldeflist)
1911 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1912 errmsg(
"column \"%s\" cannot be declared SETOF",
1916 &attrtype, &attrtypmod);
1927 rtfunc->funccolnames =
lappend(rtfunc->funccolnames,
1929 rtfunc->funccoltypes =
lappend_oid(rtfunc->funccoltypes,
1931 rtfunc->funccoltypmods =
lappend_int(rtfunc->funccoltypmods,
1933 rtfunc->funccolcollations =
lappend_oid(rtfunc->funccolcollations,
1953 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1954 errmsg(
"function \"%s\" in FROM has unsupported return type %s",
1959 rtfunc->funccolcount = tupdesc->
natts;
1963 functupdescs[funcno] = tupdesc;
1964 totalatts += tupdesc->
natts;
1980 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1981 errmsg(
"functions in FROM can return at most %d columns",
1989 for (
i = 0;
i < nfuncs;
i++)
1991 for (
j = 1;
j <= functupdescs[
i]->
natts;
j++)
2007 Assert(natts == totalatts);
2012 tupdesc = functupdescs[0];
2024 rte->lateral = lateral;
2025 rte->inFromCl = inFromCl;
2065 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2066 errmsg(
"functions in FROM can return at most %d columns",
2078 rte->coltypes = tf->coltypes;
2079 rte->coltypmods = tf->coltypmods;
2080 rte->colcollations = tf->colcollations;
2095 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2096 errmsg(
"%s function has %d columns available but %d columns specified",
2108 rte->lateral = lateral;
2109 rte->inFromCl = inFromCl;
2123 rte->coltypes, rte->coltypmods,
2124 rte->colcollations);
2138 List *colcollations,
2155 rte->coltypes = coltypes;
2156 rte->coltypmods = coltypmods;
2157 rte->colcollations = colcollations;
2165 while (numaliases < numcolumns)
2170 snprintf(attrname,
sizeof(attrname),
"column%d", numaliases);
2174 if (numcolumns < numaliases)
2176 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2177 errmsg(
"VALUES lists \"%s\" have %d columns available but %d columns specified",
2178 refname, numcolumns, numaliases)));
2188 rte->lateral = lateral;
2189 rte->inFromCl = inFromCl;
2203 rte->coltypes, rte->coltypmods,
2204 rte->colcollations);
2224 Alias *join_using_alias,
2241 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2242 errmsg(
"joins can have at most %d columns",
2249 rte->joinmergedcols = nummergedcols;
2250 rte->joinaliasvars = aliasvars;
2251 rte->joinleftcols = leftcols;
2252 rte->joinrightcols = rightcols;
2253 rte->join_using_alias = join_using_alias;
2266 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2267 errmsg(
"join expression \"%s\" has %d columns available but %d columns specified",
2278 rte->lateral =
false;
2279 rte->inFromCl = inFromCl;
2294 nsitem->
p_rte = rte;
2327 int n_dontexpand_columns = 0;
2338 Assert(cte->cterecursive || !rte->self_reference);
2340 if (!rte->self_reference)
2356 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2357 errmsg(
"WITH query \"%s\" does not have a RETURNING clause",
2362 rte->coltypes =
list_copy(cte->ctecoltypes);
2363 rte->coltypmods =
list_copy(cte->ctecoltypmods);
2364 rte->colcollations =
list_copy(cte->ctecolcollations);
2375 foreach(lc, cte->ctecolnames)
2378 if (varattno > numaliases)
2381 if (varattno < numaliases)
2383 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2384 errmsg(
"table \"%s\" has %d columns available but %d columns specified",
2385 refname, varattno, numaliases)));
2389 if (cte->search_clause)
2391 rte->eref->colnames =
lappend(rte->eref->colnames,
makeString(cte->search_clause->search_seq_column));
2392 if (cte->search_clause->search_breadth_first)
2393 rte->coltypes =
lappend_oid(rte->coltypes, RECORDOID);
2395 rte->coltypes =
lappend_oid(rte->coltypes, RECORDARRAYOID);
2396 rte->coltypmods =
lappend_int(rte->coltypmods, -1);
2399 n_dontexpand_columns += 1;
2402 if (cte->cycle_clause)
2404 rte->eref->colnames =
lappend(rte->eref->colnames,
makeString(cte->cycle_clause->cycle_mark_column));
2405 rte->coltypes =
lappend_oid(rte->coltypes, cte->cycle_clause->cycle_mark_type);
2406 rte->coltypmods =
lappend_int(rte->coltypmods, cte->cycle_clause->cycle_mark_typmod);
2407 rte->colcollations =
lappend_oid(rte->colcollations, cte->cycle_clause->cycle_mark_collation);
2409 rte->eref->colnames =
lappend(rte->eref->colnames,
makeString(cte->cycle_clause->cycle_path_column));
2410 rte->coltypes =
lappend_oid(rte->coltypes, RECORDARRAYOID);
2411 rte->coltypmods =
lappend_int(rte->coltypmods, -1);
2414 n_dontexpand_columns += 2;
2423 rte->lateral =
false;
2424 rte->inFromCl = inFromCl;
2438 rte->coltypes, rte->coltypmods,
2439 rte->colcollations);
2446 for (
int i = 0;
i < n_dontexpand_columns;
i++)
2509 rte->coltypes =
NIL;
2510 rte->coltypmods =
NIL;
2511 rte->colcollations =
NIL;
2512 for (attno = 1; attno <= tupdesc->
natts; ++attno)
2516 if (att->attisdropped)
2520 rte->coltypmods =
lappend_int(rte->coltypmods, 0);
2527 elog(
ERROR,
"atttypid is invalid for non-dropped column in \"%s\"",
2529 rte->coltypes =
lappend_oid(rte->coltypes, att->atttypid);
2530 rte->coltypmods =
lappend_int(rte->coltypmods, att->atttypmod);
2531 rte->colcollations =
lappend_oid(rte->colcollations,
2542 rte->lateral =
false;
2543 rte->inFromCl = inFromCl;
2586 coltypes = coltypmods = colcollations =
NIL;
2587 foreach(lc, groupClauses)
2590 char *colname = te->resname ?
pstrdup(te->resname) :
"?column?";
2605 rte->groupexprs = groupexprs;
2613 rte->lateral =
false;
2614 rte->inFromCl =
false;
2628 coltypes, coltypmods, colcollations);
2668 else if (refname != NULL)
2677 if (strcmp(refname, thisrel->
relname) == 0)
2694 bool addToRelNameSpace,
bool addToVarNameSpace)
2703 if (addToRelNameSpace || addToVarNameSpace)
2733 int location,
bool include_dropped,
2748 rtindex, sublevels_up, location,
2749 include_dropped, colnames, colvars);
2776 elog(
ERROR,
"too few column names for subquery %s",
2777 rte->eref->aliasname);
2790 varnode =
makeVar(rtindex, varattno,
2797 *colvars =
lappend(*colvars, varnode);
2800 aliasp_item =
lnext(rte->eref->colnames, aliasp_item);
2818 if (rtfunc->funccolnames !=
NIL)
2831 rtfunc->funccolcount, atts_done,
2832 rtindex, sublevels_up, location,
2833 include_dropped, colnames, colvars);
2839 *colnames =
lappend(*colnames,
2847 varnode =
makeVar(rtindex, atts_done + 1,
2854 *colvars =
lappend(*colvars, varnode);
2867 rtfunc->funccolcount);
2879 l2, rtfunc->funccoltypmods,
2880 l3, rtfunc->funccolcollations)
2895 *colvars =
lappend(*colvars, varnode);
2902 elog(
ERROR,
"function in FROM has unsupported return type");
2904 atts_done += rtfunc->funccolcount;
2911 *colnames =
lappend(*colnames,
2912 llast(rte->eref->colnames));
2923 *colvars =
lappend(*colvars, varnode);
2937 forboth(colname, rte->eref->colnames, aliasvar, rte->joinaliasvars)
2953 if (include_dropped)
2956 *colnames =
lappend(*colnames,
2977 *colnames =
lappend(*colnames,
3000 varnode =
makeVar(rtindex, varattno,
3007 *colvars =
lappend(*colvars, varnode);
3025 lcm, rte->coltypmods,
3026 lcc, rte->colcollations)
3041 *colnames =
lappend(*colnames,
3044 else if (include_dropped)
3045 *colnames =
lappend(*colnames,
3048 aliasp_item =
lnext(rte->eref->colnames, aliasp_item);
3057 varnode =
makeVar(rtindex, varattno,
3058 coltype, coltypmod, colcoll,
3062 *colvars =
lappend(*colvars, varnode);
3064 else if (include_dropped)
3092 int location,
bool include_dropped,
3100 rtindex, sublevels_up,
3101 location, include_dropped,
3117 int rtindex,
int sublevels_up,
3118 int location,
bool include_dropped,
3127 Assert(count <= tupdesc->natts);
3128 for (varattno = 0; varattno < count; varattno++)
3132 if (attr->attisdropped)
3134 if (include_dropped)
3174 varnode =
makeVar(rtindex, varattno + offset + 1,
3175 attr->atttypid, attr->atttypmod,
3180 *colvars =
lappend(*colvars, varnode);
3198 int sublevels_up,
int location,
3211 const char *colname =
strVal(colnameval);
3218 else if (colname[0])
3237 result =
lappend(result, var);
3239 *colnames =
lappend(*colnames, colnameval);
3262 int sublevels_up,
bool require_col_privs,
int location)
3284 Assert(perminfo != NULL);
3298 te_list =
lappend(te_list, te);
3300 if (require_col_privs)
3355 elog(
ERROR,
"invalid attnum %d for rangetable entry %s",
3356 attnum, rte->eref->aliasname);
3383 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
3386 result = att_tup->attisdropped;
3427 result = (aliasvar == NULL);
3447 if (
attnum > atts_done &&
3448 attnum <= atts_done + rtfunc->funccolcount)
3453 if (rtfunc->funccolnames !=
NIL)
3467 return att_tup->attisdropped;
3472 atts_done += rtfunc->funccolcount;
3481 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3482 errmsg(
"column %d of relation \"%s\" does not exist",
3484 rte->eref->aliasname)));
3491 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3492 errmsg(
"column %d of relation \"%s\" does not exist",
3494 rte->eref->aliasname)));
3522 if (tle->
resno == resno)
3542 if (rc->
rti == rtindex)
3595 return sysatt->attnum;
3615 return &sysatt->attname;
3618 elog(
ERROR,
"invalid attribute number %d", attid);
3637 return sysatt->atttypid;
3640 elog(
ERROR,
"invalid attribute number %d", attid);
3658 elog(
ERROR,
"invalid attribute number %d", attid);
3672 const char *badAlias = NULL;
3691 if (rte && rte->alias &&
3692 strcmp(rte->eref->aliasname, relation->
relname) != 0)
3700 if (nsitem && nsitem->
p_rte == rte)
3701 badAlias = rte->eref->aliasname;
3708 errmsg(
"invalid reference to FROM-clause entry for table \"%s\"",
3710 errhint(
"Perhaps you meant to reference the table alias \"%s\".",
3717 errmsg(
"invalid reference to FROM-clause entry for table \"%s\"",
3719 errdetail(
"There is an entry for table \"%s\", but it cannot be referenced from this part of the query.",
3720 rte->eref->aliasname),
3722 errhint(
"To reference that table, you must mark this subquery with LATERAL.") : 0,
3728 errmsg(
"missing FROM-clause entry for table \"%s\"",
3741 const char *
relname,
const char *colname,
int location)
3764 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3767 errmsg(
"column \"%s\" does not exist", colname),
3768 errdetail(
"There are columns named \"%s\", but they are in tables that cannot be referenced from this part of the query.",
3774 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3777 errmsg(
"column \"%s\" does not exist", colname),
3778 errdetail(
"There is a column named \"%s\" in table \"%s\", but it cannot be referenced from this part of the query.",
3779 colname,
state->rexact1->eref->aliasname),
3781 errhint(
"To reference that column, you must mark this subquery with LATERAL.") :
3783 errhint(
"To reference that column, you must use a table-qualified name.") : 0,
3787 if (!
state->rsecond)
3792 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3795 errmsg(
"column \"%s\" does not exist", colname),
3799 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3802 errmsg(
"column \"%s\" does not exist", colname),
3803 errhint(
"Perhaps you meant to reference the column \"%s.%s\".",
3804 state->rfirst->eref->aliasname,
3806 state->first - 1))),
3813 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3816 errmsg(
"column \"%s\" does not exist", colname),
3817 errhint(
"Perhaps you meant to reference the column \"%s.%s\" or the column \"%s.%s\".",
3818 state->rfirst->eref->aliasname,
3821 state->rsecond->eref->aliasname,
3823 state->second - 1))),
3835 while (pstate != NULL)
3843 if (nsitem->
p_rte == rte)
3915 foreach(rtable, query->
rtable)
3922 char relpersistence = rel->
rd_rel->relpersistence;
3925 if (relpersistence == RELPERSISTENCE_TEMP)
3954 Assert(rte->perminfoindex == 0);
3959 perminfo->
inh = rte->
inh;
3962 *rteperminfos =
lappend(*rteperminfos, perminfo);
3982 if (rte->perminfoindex == 0 ||
3984 elog(
ERROR,
"invalid perminfoindex %u in RTE with relid %u",
3985 rte->perminfoindex, rte->
relid);
3987 rte->perminfoindex - 1);
3989 elog(
ERROR,
"permission info at index %u (with relid=%u) does not match provided RTE (with relid=%u)",
3990 rte->perminfoindex, perminfo->
relid, rte->
relid);
#define InvalidAttrNumber
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
#define Assert(condition)
#define OidIsValid(objectId)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
char * get_func_result_name(Oid functionId)
TupleDesc get_expr_result_tupdesc(Node *expr, bool noError)
TypeFuncClass get_expr_result_type(Node *expr, Oid *resultTypeId, TupleDesc *resultTupleDesc)
@ TYPEFUNC_COMPOSITE_DOMAIN
const FormData_pg_attribute * SystemAttributeDefinition(AttrNumber attno)
void CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind, int flags)
const FormData_pg_attribute * SystemAttributeByName(const char *attname)
#define CHKATYPE_ANYRECORD
#define HeapTupleIsValid(tuple)
#define MaxTupleAttributeNumber
#define MaxHeapAttributeNumber
if(TABLE==NULL||TABLE_index==NULL)
List * list_truncate(List *list, int new_size)
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
List * list_copy(const List *oldlist)
List * list_copy_tail(const List *oldlist, int nskip)
List * list_concat(List *list1, const List *list2)
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
Oid get_relname_relid(const char *relname, Oid relnamespace)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Alias * makeAlias(const char *aliasname, List *colnames)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
char * pstrdup(const char *in)
void * palloc0(Size size)
int namestrcmp(Name name, const char *str)
Oid LookupNamespaceNoError(const char *nspname)
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
int exprLocation(const Node *expr)
#define query_tree_walker(q, w, c, f)
#define expression_tree_walker(n, w, c)
#define QTW_IGNORE_JOINALIASES
#define IsA(nodeptr, _type_)
EphemeralNamedRelationMetadata get_visible_ENR(ParseState *pstate, const char *refname)
bool name_matches_visible_ENR(ParseState *pstate, const char *refname)
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
int parser_errposition(ParseState *pstate, int location)
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
@ EXPR_KIND_GENERATED_COLUMN
@ EXPR_KIND_CHECK_CONSTRAINT
static bool rte_visible_if_lateral(ParseState *pstate, RangeTblEntry *rte)
static void expandRelation(Oid relid, Alias *eref, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
void markNullableIfNeeded(ParseState *pstate, Var *var)
ParseNamespaceItem * addRangeTableEntryForCTE(ParseState *pstate, CommonTableExpr *cte, Index levelsup, RangeVar *rv, bool inFromCl)
RangeTblEntry * GetRTEByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
static void expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
ParseNamespaceItem * addRangeTableEntry(ParseState *pstate, RangeVar *relation, Alias *alias, bool inh, bool inFromCl)
void errorMissingColumn(ParseState *pstate, const char *relname, const char *colname, int location)
static int specialAttNum(const char *attname)
RTEPermissionInfo * addRTEPermissionInfo(List **rteperminfos, RangeTblEntry *rte)
static ParseNamespaceItem * scanNameSpaceForRelid(ParseState *pstate, Oid relid, int location)
static FuzzyAttrMatchState * searchRangeTableForCol(ParseState *pstate, const char *alias, const char *colname, int location)
ParseNamespaceItem * addRangeTableEntryForJoin(ParseState *pstate, List *colnames, ParseNamespaceColumn *nscolumns, JoinType jointype, int nummergedcols, List *aliasvars, List *leftcols, List *rightcols, Alias *join_using_alias, Alias *alias, bool inFromCl)
Oid attnumCollationId(Relation rd, int attid)
ParseNamespaceItem * addRangeTableEntryForGroup(ParseState *pstate, List *groupClauses)
void markVarForSelectPriv(ParseState *pstate, Var *var)
RowMarkClause * get_parse_rowmark(Query *qry, Index rtindex)
CommonTableExpr * scanNameSpaceForCTE(ParseState *pstate, const char *refname, Index *ctelevelsup)
static RangeTblEntry * searchRangeTableForRel(ParseState *pstate, RangeVar *relation)
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
static ParseNamespaceItem * scanNameSpaceForRefname(ParseState *pstate, const char *refname, int location)
void errorMissingRTE(ParseState *pstate, RangeVar *relation)
static bool isFutureCTE(ParseState *pstate, const char *refname)
bool get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
static void updateFuzzyAttrMatchState(int fuzzy_rte_penalty, FuzzyAttrMatchState *fuzzystate, RangeTblEntry *rte, const char *actual, const char *match, int attnum)
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
const NameData * attnumAttName(Relation rd, int attid)
Relation parserOpenTable(ParseState *pstate, const RangeVar *relation, int lockmode)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
static int scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, Alias *eref, const char *colname, int location, int fuzzy_rte_penalty, FuzzyAttrMatchState *fuzzystate)
#define MAX_FUZZY_DISTANCE
static ParseNamespaceItem * buildNSItemFromTupleDesc(RangeTblEntry *rte, Index rtindex, RTEPermissionInfo *perminfo, TupleDesc tupdesc)
ParseNamespaceItem * GetNSItemByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
ParseNamespaceItem * addRangeTableEntryForSubquery(ParseState *pstate, Query *subquery, Alias *alias, bool lateral, bool inFromCl)
Node * scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, const char *colname, int location)
ParseNamespaceItem * refnameNamespaceItem(ParseState *pstate, const char *schemaname, const char *refname, int location, int *sublevels_up)
char * get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
bool scanNameSpaceForENR(ParseState *pstate, const char *refname)
bool isLockedRefname(ParseState *pstate, const char *refname)
Oid attnumTypeId(Relation rd, int attid)
ParseNamespaceItem * addRangeTableEntryForFunction(ParseState *pstate, List *funcnames, List *funcexprs, List *coldeflists, RangeFunction *rangefunc, bool lateral, bool inFromCl)
static ParseNamespaceItem * findNSItemForRTE(ParseState *pstate, RangeTblEntry *rte)
Node * colNameToVar(ParseState *pstate, const char *colname, bool localonly, int location)
static bool rte_visible_if_qualified(ParseState *pstate, RangeTblEntry *rte)
static void markRTEForSelectPriv(ParseState *pstate, int rtindex, AttrNumber col)
ParseNamespaceItem * addRangeTableEntryForTableFunc(ParseState *pstate, TableFunc *tf, Alias *alias, bool lateral, bool inFromCl)
ParseNamespaceItem * addRangeTableEntryForValues(ParseState *pstate, List *exprs, List *coltypes, List *coltypmods, List *colcollations, Alias *alias, bool lateral, bool inFromCl)
List * expandNSItemVars(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location, List **colnames)
static char * chooseScalarFunctionAlias(Node *funcexpr, char *funcname, Alias *alias, int nfuncs)
static ParseNamespaceItem * buildNSItemFromLists(RangeTblEntry *rte, Index rtindex, List *coltypes, List *coltypmods, List *colcollations)
List * expandNSItemAttrs(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, bool require_col_privs, int location)
bool isQueryUsingTempRelation(Query *query)
ParseNamespaceItem * addRangeTableEntryForENR(ParseState *pstate, RangeVar *rv, bool inFromCl)
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
CommonTableExpr * GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte, int rtelevelsup)
static void buildRelationAliases(TupleDesc tupdesc, Alias *alias, Alias *eref)
int attnameAttNum(Relation rd, const char *attname, bool sysColOK)
void checkNameSpaceConflicts(ParseState *pstate, List *namespace1, List *namespace2)
static void check_lateral_ref_ok(ParseState *pstate, ParseNamespaceItem *nsitem, int location)
static bool isQueryUsingTempRelation_walker(Node *node, void *context)
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
Oid GetColumnDefCollation(ParseState *pstate, const ColumnDef *coldef, Oid typeOid)
#define rt_fetch(rangetable_index, rangetable)
FormData_pg_attribute * Form_pg_attribute
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
static Oid list_nth_oid(const List *list, int n)
#define forthree(cell1, list1, cell2, list2, cell3, list3)
static ListCell * list_head(const List *l)
static ListCell * list_nth_cell(const List *list, int n)
static void * list_nth(const List *list, int n)
#define list_nth_node(type, list, n)
static ListCell * lnext(const List *l, const ListCell *c)
#define ERRCODE_UNDEFINED_TABLE
static Datum Int16GetDatum(int16 X)
static Datum ObjectIdGetDatum(Oid X)
TupleDesc ENRMetadataGetTupDesc(EphemeralNamedRelationMetadata enrmd)
#define RelationGetRelid(relation)
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
ParseNamespaceColumn * p_nscolumns
RTEPermissionInfo * p_perminfo
ParseState * parentParseState
ParseNamespaceItem * p_target_nsitem
ParseExprKind p_expr_kind
bool p_locked_from_parent
#define FirstLowInvalidHeapAttributeNumber
#define TableOidAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
#define SearchSysCacheExists2(cacheId, key1, key2)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Relation table_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
TupleDesc CreateTemplateTupleDesc(int natts)
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
void TupleDescCopyEntry(TupleDesc dst, AttrNumber dstAttno, TupleDesc src, AttrNumber srcAttno)
#define TupleDescAttr(tupdesc, i)
String * makeString(char *str)
int varstr_levenshtein_less_equal(const char *source, int slen, const char *target, int tlen, int ins_c, int del_c, int sub_c, int max_d, bool trusted)