72#define MAX_FUZZY_DISTANCE 3
84 const char *colname,
int location,
85 int fuzzy_rte_penalty,
90 int rtindex,
int sublevels_up,
92 int location,
bool include_dropped,
95 int count,
int offset,
96 int rtindex,
int sublevels_up,
98 int location,
bool include_dropped,
131 const char *schemaname,
141 if (schemaname != NULL)
161 while (pstate != NULL)
221 (
errcode(ERRCODE_AMBIGUOUS_ALIAS),
222 errmsg(
"table reference \"%s\" is ambiguous",
263 rte->relid == relid &&
268 (
errcode(ERRCODE_AMBIGUOUS_ALIAS),
269 errmsg(
"table reference %u is ambiguous",
301 if (strcmp(cte->
ctename, refname) == 0)
303 *ctelevelsup = levelsup;
327 if (strcmp(cte->
ctename, refname) == 0)
362 const char *refname = relation->
relname;
366 Index ctelevelsup = 0;
409 strcmp(rte->
ctename, refname) == 0)
413 strcmp(rte->
enrname, refname) == 0)
415 if (strcmp(rte->eref->aliasname, refname) == 0)
443 foreach(l1, namespace1)
453 foreach(l2, namespace2)
461 if (strcmp(aliasname2, aliasname1) != 0)
465 rte1->relid != rte2->relid)
468 (
errcode(ERRCODE_DUPLICATE_ALIAS),
469 errmsg(
"table name \"%s\" specified more than once",
497 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
498 errmsg(
"invalid reference to FROM-clause entry for table \"%s\"",
502 errhint(
"There is an entry for table \"%s\", but it cannot be referenced from this part of the query.",
504 errdetail(
"The combining JOIN type must be INNER or LEFT for a LATERAL reference."),
520 while (sublevels_up-- > 0)
532 elog(
ERROR,
"nsitem not found (internal error)");
545 while (sublevels_up-- > 0)
568 while (levelsup-- > 0)
593 const char *actual,
const char *match,
int attnum)
599 if (fuzzy_rte_penalty > fuzzystate->
distance)
606 if (actual[0] ==
'\0')
610 matchlen = strlen(match);
622 if (columndistance > matchlen / 2)
629 columndistance += fuzzy_rte_penalty;
635 if (columndistance < fuzzystate->distance)
638 fuzzystate->
distance = columndistance;
643 else if (columndistance == fuzzystate->
distance)
646 if (fuzzystate->
rsecond != NULL)
655 fuzzystate->
rfirst = NULL;
658 else if (fuzzystate->
rfirst != NULL)
685 int sublevels_up,
const char *colname,
int location)
706 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
707 errmsg(
"system column \"%s\" reference in check constraint is invalid",
719 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
720 errmsg(
"cannot use system column \"%s\" in column generation expression",
730 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
731 errmsg(
"cannot use system column \"%s\" in MERGE WHEN condition",
744 (
errcode(ERRCODE_UNDEFINED_COLUMN),
745 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
769 sysatt->attcollation,
813 const char *colname,
int location,
814 int fuzzy_rte_penalty,
839 if (strcmp(attcolname, colname) == 0)
843 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
844 errmsg(
"column reference \"%s\" is ambiguous",
851 if (fuzzystate != NULL)
853 rte, attcolname, colname,
attnum);
869 rte->relkind != RELKIND_COMPOSITE_TYPE)
898 int sublevels_up = 0;
901 while (pstate != NULL)
925 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
926 errmsg(
"column reference \"%s\" is ambiguous",
934 if (result != NULL || localonly)
970 fuzzystate->
rfirst = NULL;
975 while (pstate != NULL)
982 int fuzzy_rte_penalty = 0;
1003 rte->eref->aliasname,
1004 strlen(rte->eref->aliasname),
1017 fuzzy_rte_penalty, fuzzystate);
1020 if (fuzzystate->
rexact1 == NULL)
1048 int rtindex = var->
varno;
1066 var->varnullingrels =
bms_union(var->varnullingrels, relids);
1108 elog(
ERROR,
"could not find JoinExpr for whole-row reference");
1119 int varno = ((
JoinExpr *)
j->larg)->rtindex;
1124 elog(
ERROR,
"unrecognized node type: %d",
1134 int varno = ((
JoinExpr *)
j->rarg)->rtindex;
1139 elog(
ERROR,
"unrecognized node type: %d",
1190 int maxattrs = tupdesc->
natts;
1214 for (varattno = 0; varattno < maxattrs; varattno++)
1219 if (attr->attisdropped)
1231 aliaslc =
lnext(aliaslist, aliaslc);
1246 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
1247 errmsg(
"table \"%s\" has %d columns available but %d columns specified",
1248 eref->
aliasname, maxattrs - numdropped, numaliases)));
1266 Alias *alias,
int nfuncs)
1286 if (nfuncs == 1 && alias)
1311 int maxattrs = tupdesc->
natts;
1321 for (varattno = 0; varattno < maxattrs; varattno++)
1326 if (attr->attisdropped)
1329 nscolumns[varattno].
p_varno = rtindex;
1330 nscolumns[varattno].
p_varattno = varattno + 1;
1331 nscolumns[varattno].
p_vartype = attr->atttypid;
1332 nscolumns[varattno].
p_vartypmod = attr->atttypmod;
1333 nscolumns[varattno].
p_varcollid = attr->attcollation;
1341 nsitem->
p_rte = rte;
1392 nscolumns[varattno].
p_varno = rtindex;
1393 nscolumns[varattno].
p_varattno = varattno + 1;
1405 nsitem->
p_rte = rte;
1443 errmsg(
"relation \"%s.%s\" does not exist",
1456 errmsg(
"relation \"%s\" does not exist",
1458 errdetail(
"There is a WITH item named \"%s\", but it cannot be referenced from this part of the query.",
1460 errhint(
"Use WITH RECURSIVE, or re-order the WITH items to remove forward references.")));
1464 errmsg(
"relation \"%s\" does not exist",
1517 rte->relkind = rel->
rd_rel->relkind;
1518 rte->rellockmode = lockmode;
1533 rte->lateral =
false;
1534 rte->inFromCl = inFromCl;
1602 rte->relkind = rel->
rd_rel->relkind;
1603 rte->rellockmode = lockmode;
1618 rte->lateral =
false;
1619 rte->inFromCl = inFromCl;
1677 coltypes = coltypmods = colcollations =
NIL;
1687 if (varattno > numaliases)
1691 attrname =
pstrdup(te->resname);
1701 if (varattno < numaliases)
1703 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
1704 errmsg(
"table \"%s\" has %d columns available but %d columns specified",
1705 eref->
aliasname, varattno, numaliases)));
1715 rte->lateral = lateral;
1716 rte->inFromCl = inFromCl;
1730 coltypes, coltypmods, colcollations);
1798 forthree(lc1, funcexprs, lc2, funcnames, lc3, coldeflists)
1809 rtfunc->funccolnames =
NIL;
1810 rtfunc->funccoltypes =
NIL;
1811 rtfunc->funccoltypmods =
NIL;
1812 rtfunc->funccolcollations =
NIL;
1813 rtfunc->funcparams = NULL;
1828 if (coldeflist !=
NIL)
1830 switch (functypclass)
1843 if (
exprType(funcexpr) == RECORDOID)
1845 (
errcode(ERRCODE_SYNTAX_ERROR),
1846 errmsg(
"a column definition list is redundant for a function with OUT parameters"),
1851 (
errcode(ERRCODE_SYNTAX_ERROR),
1852 errmsg(
"a column definition list is redundant for a function returning a named composite type"),
1858 (
errcode(ERRCODE_SYNTAX_ERROR),
1859 errmsg(
"a column definition list is only allowed for functions returning \"record\""),
1869 (
errcode(ERRCODE_SYNTAX_ERROR),
1870 errmsg(
"a column definition list is required for functions returning \"record\""),
1906 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1907 errmsg(
"column definition lists can have at most %d entries",
1913 foreach(col, coldeflist)
1924 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1925 errmsg(
"column \"%s\" cannot be declared SETOF",
1929 &attrtype, &attrtypmod);
1940 rtfunc->funccolnames =
lappend(rtfunc->funccolnames,
1942 rtfunc->funccoltypes =
lappend_oid(rtfunc->funccoltypes,
1944 rtfunc->funccoltypmods =
lappend_int(rtfunc->funccoltypmods,
1946 rtfunc->funccolcollations =
lappend_oid(rtfunc->funccolcollations,
1966 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1967 errmsg(
"function \"%s\" in FROM has unsupported return type %s",
1972 rtfunc->funccolcount = tupdesc->
natts;
1976 functupdescs[funcno] = tupdesc;
1977 totalatts += tupdesc->
natts;
1993 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1994 errmsg(
"functions in FROM can return at most %d columns",
2002 for (
i = 0;
i < nfuncs;
i++)
2004 for (
j = 1;
j <= functupdescs[
i]->
natts;
j++)
2020 Assert(natts == totalatts);
2025 tupdesc = functupdescs[0];
2037 rte->lateral = lateral;
2038 rte->inFromCl = inFromCl;
2078 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2079 errmsg(
"functions in FROM can return at most %d columns",
2091 rte->coltypes = tf->coltypes;
2092 rte->coltypmods = tf->coltypmods;
2093 rte->colcollations = tf->colcollations;
2108 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2109 errmsg(
"%s function has %d columns available but %d columns specified",
2121 rte->lateral = lateral;
2122 rte->inFromCl = inFromCl;
2136 rte->coltypes, rte->coltypmods,
2137 rte->colcollations);
2151 List *colcollations,
2168 rte->coltypes = coltypes;
2169 rte->coltypmods = coltypmods;
2170 rte->colcollations = colcollations;
2178 while (numaliases < numcolumns)
2183 snprintf(attrname,
sizeof(attrname),
"column%d", numaliases);
2187 if (numcolumns < numaliases)
2189 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2190 errmsg(
"VALUES lists \"%s\" have %d columns available but %d columns specified",
2191 refname, numcolumns, numaliases)));
2201 rte->lateral = lateral;
2202 rte->inFromCl = inFromCl;
2216 rte->coltypes, rte->coltypmods,
2217 rte->colcollations);
2237 Alias *join_using_alias,
2254 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2255 errmsg(
"joins can have at most %d columns",
2262 rte->joinmergedcols = nummergedcols;
2263 rte->joinaliasvars = aliasvars;
2264 rte->joinleftcols = leftcols;
2265 rte->joinrightcols = rightcols;
2266 rte->join_using_alias = join_using_alias;
2279 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2280 errmsg(
"join expression \"%s\" has %d columns available but %d columns specified",
2291 rte->lateral =
false;
2292 rte->inFromCl = inFromCl;
2307 nsitem->
p_rte = rte;
2341 int n_dontexpand_columns = 0;
2352 Assert(cte->cterecursive || !rte->self_reference);
2354 if (!rte->self_reference)
2370 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2371 errmsg(
"WITH query \"%s\" does not have a RETURNING clause",
2376 rte->coltypes =
list_copy(cte->ctecoltypes);
2377 rte->coltypmods =
list_copy(cte->ctecoltypmods);
2378 rte->colcollations =
list_copy(cte->ctecolcollations);
2389 foreach(lc, cte->ctecolnames)
2392 if (varattno > numaliases)
2395 if (varattno < numaliases)
2397 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2398 errmsg(
"table \"%s\" has %d columns available but %d columns specified",
2399 refname, varattno, numaliases)));
2403 if (cte->search_clause)
2405 rte->eref->colnames =
lappend(rte->eref->colnames,
makeString(cte->search_clause->search_seq_column));
2406 if (cte->search_clause->search_breadth_first)
2407 rte->coltypes =
lappend_oid(rte->coltypes, RECORDOID);
2409 rte->coltypes =
lappend_oid(rte->coltypes, RECORDARRAYOID);
2410 rte->coltypmods =
lappend_int(rte->coltypmods, -1);
2413 n_dontexpand_columns += 1;
2416 if (cte->cycle_clause)
2418 rte->eref->colnames =
lappend(rte->eref->colnames,
makeString(cte->cycle_clause->cycle_mark_column));
2419 rte->coltypes =
lappend_oid(rte->coltypes, cte->cycle_clause->cycle_mark_type);
2420 rte->coltypmods =
lappend_int(rte->coltypmods, cte->cycle_clause->cycle_mark_typmod);
2421 rte->colcollations =
lappend_oid(rte->colcollations, cte->cycle_clause->cycle_mark_collation);
2423 rte->eref->colnames =
lappend(rte->eref->colnames,
makeString(cte->cycle_clause->cycle_path_column));
2424 rte->coltypes =
lappend_oid(rte->coltypes, RECORDARRAYOID);
2425 rte->coltypmods =
lappend_int(rte->coltypmods, -1);
2428 n_dontexpand_columns += 2;
2437 rte->lateral =
false;
2438 rte->inFromCl = inFromCl;
2452 rte->coltypes, rte->coltypmods,
2453 rte->colcollations);
2460 for (
int i = 0;
i < n_dontexpand_columns;
i++)
2523 rte->coltypes =
NIL;
2524 rte->coltypmods =
NIL;
2525 rte->colcollations =
NIL;
2526 for (attno = 1; attno <= tupdesc->
natts; ++attno)
2530 if (att->attisdropped)
2534 rte->coltypmods =
lappend_int(rte->coltypmods, 0);
2541 elog(
ERROR,
"atttypid is invalid for non-dropped column in \"%s\"",
2543 rte->coltypes =
lappend_oid(rte->coltypes, att->atttypid);
2544 rte->coltypmods =
lappend_int(rte->coltypmods, att->atttypmod);
2545 rte->colcollations =
lappend_oid(rte->colcollations,
2556 rte->lateral =
false;
2557 rte->inFromCl = inFromCl;
2600 coltypes = coltypmods = colcollations =
NIL;
2601 foreach(lc, groupClauses)
2604 char *colname = te->resname ?
pstrdup(te->resname) :
"?column?";
2619 rte->groupexprs = groupexprs;
2627 rte->lateral =
false;
2628 rte->inFromCl =
false;
2642 coltypes, coltypmods, colcollations);
2682 else if (refname != NULL)
2691 if (strcmp(refname, thisrel->
relname) == 0)
2708 bool addToRelNameSpace,
bool addToVarNameSpace)
2717 if (addToRelNameSpace || addToVarNameSpace)
2749 int location,
bool include_dropped,
2764 rtindex, sublevels_up, returning_type, location,
2765 include_dropped, colnames, colvars);
2792 elog(
ERROR,
"too few column names for subquery %s",
2793 rte->eref->aliasname);
2806 varnode =
makeVar(rtindex, varattno,
2814 *colvars =
lappend(*colvars, varnode);
2817 aliasp_item =
lnext(rte->eref->colnames, aliasp_item);
2835 if (rtfunc->funccolnames !=
NIL)
2848 rtfunc->funccolcount, atts_done,
2849 rtindex, sublevels_up,
2850 returning_type, location,
2851 include_dropped, colnames, colvars);
2857 *colnames =
lappend(*colnames,
2865 varnode =
makeVar(rtindex, atts_done + 1,
2873 *colvars =
lappend(*colvars, varnode);
2886 rtfunc->funccolcount);
2898 l2, rtfunc->funccoltypmods,
2899 l3, rtfunc->funccolcollations)
2915 *colvars =
lappend(*colvars, varnode);
2922 elog(
ERROR,
"function in FROM has unsupported return type");
2924 atts_done += rtfunc->funccolcount;
2931 *colnames =
lappend(*colnames,
2932 llast(rte->eref->colnames));
2944 *colvars =
lappend(*colvars, varnode);
2958 forboth(colname, rte->eref->colnames, aliasvar, rte->joinaliasvars)
2974 if (include_dropped)
2977 *colnames =
lappend(*colnames,
2998 *colnames =
lappend(*colnames,
3021 varnode =
makeVar(rtindex, varattno,
3029 *colvars =
lappend(*colvars, varnode);
3047 lcm, rte->coltypmods,
3048 lcc, rte->colcollations)
3063 *colnames =
lappend(*colnames,
3066 else if (include_dropped)
3067 *colnames =
lappend(*colnames,
3070 aliasp_item =
lnext(rte->eref->colnames, aliasp_item);
3079 varnode =
makeVar(rtindex, varattno,
3080 coltype, coltypmod, colcoll,
3085 *colvars =
lappend(*colvars, varnode);
3087 else if (include_dropped)
3116 int location,
bool include_dropped,
3124 rtindex, sublevels_up, returning_type,
3125 location, include_dropped,
3141 int rtindex,
int sublevels_up,
3143 int location,
bool include_dropped,
3152 Assert(count <= tupdesc->natts);
3153 for (varattno = 0; varattno < count; varattno++)
3157 if (attr->attisdropped)
3159 if (include_dropped)
3199 varnode =
makeVar(rtindex, varattno + offset + 1,
3200 attr->atttypid, attr->atttypmod,
3206 *colvars =
lappend(*colvars, varnode);
3224 int sublevels_up,
int location,
3237 const char *colname =
strVal(colnameval);
3244 else if (colname[0])
3264 result =
lappend(result, var);
3266 *colnames =
lappend(*colnames, colnameval);
3289 int sublevels_up,
bool require_col_privs,
int location)
3311 Assert(perminfo != NULL);
3325 te_list =
lappend(te_list, te);
3327 if (require_col_privs)
3382 elog(
ERROR,
"invalid attnum %d for rangetable entry %s",
3383 attnum, rte->eref->aliasname);
3410 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
3413 result = att_tup->attisdropped;
3454 result = (aliasvar == NULL);
3474 if (
attnum > atts_done &&
3475 attnum <= atts_done + rtfunc->funccolcount)
3480 if (rtfunc->funccolnames !=
NIL)
3499 atts_done += rtfunc->funccolcount;
3508 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3509 errmsg(
"column %d of relation \"%s\" does not exist",
3511 rte->eref->aliasname)));
3518 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3519 errmsg(
"column %d of relation \"%s\" does not exist",
3521 rte->eref->aliasname)));
3549 if (tle->
resno == resno)
3569 if (rc->
rti == rtindex)
3622 return sysatt->attnum;
3642 return &sysatt->attname;
3645 elog(
ERROR,
"invalid attribute number %d", attid);
3664 return sysatt->atttypid;
3667 elog(
ERROR,
"invalid attribute number %d", attid);
3685 elog(
ERROR,
"invalid attribute number %d", attid);
3699 const char *badAlias = NULL;
3718 if (rte && rte->alias &&
3719 strcmp(rte->eref->aliasname, relation->
relname) != 0)
3727 if (nsitem && nsitem->
p_rte == rte)
3728 badAlias = rte->eref->aliasname;
3735 errmsg(
"invalid reference to FROM-clause entry for table \"%s\"",
3737 errhint(
"Perhaps you meant to reference the table alias \"%s\".",
3744 errmsg(
"invalid reference to FROM-clause entry for table \"%s\"",
3746 errdetail(
"There is an entry for table \"%s\", but it cannot be referenced from this part of the query.",
3747 rte->eref->aliasname),
3749 errhint(
"To reference that table, you must mark this subquery with LATERAL.") : 0,
3755 errmsg(
"missing FROM-clause entry for table \"%s\"",
3768 const char *
relname,
const char *colname,
int location)
3791 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3794 errmsg(
"column \"%s\" does not exist", colname),
3795 errdetail(
"There are columns named \"%s\", but they are in tables that cannot be referenced from this part of the query.",
3801 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3804 errmsg(
"column \"%s\" does not exist", colname),
3805 errdetail(
"There is a column named \"%s\" in table \"%s\", but it cannot be referenced from this part of the query.",
3806 colname,
state->rexact1->eref->aliasname),
3808 errhint(
"To reference that column, you must mark this subquery with LATERAL.") :
3810 errhint(
"To reference that column, you must use a table-qualified name.") : 0,
3814 if (!
state->rsecond)
3819 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3822 errmsg(
"column \"%s\" does not exist", colname),
3826 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3829 errmsg(
"column \"%s\" does not exist", colname),
3830 errhint(
"Perhaps you meant to reference the column \"%s.%s\".",
3831 state->rfirst->eref->aliasname,
3833 state->first - 1))),
3840 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3843 errmsg(
"column \"%s\" does not exist", colname),
3844 errhint(
"Perhaps you meant to reference the column \"%s.%s\" or the column \"%s.%s\".",
3845 state->rfirst->eref->aliasname,
3848 state->rsecond->eref->aliasname,
3850 state->second - 1))),
3862 while (pstate != NULL)
3870 if (nsitem->
p_rte == rte)
3934 Assert(rte->perminfoindex == 0);
3938 perminfo->
relid = rte->relid;
3939 perminfo->
inh = rte->
inh;
3942 *rteperminfos =
lappend(*rteperminfos, perminfo);
3962 if (rte->perminfoindex == 0 ||
3964 elog(
ERROR,
"invalid perminfoindex %u in RTE with relid %u",
3965 rte->perminfoindex, rte->relid);
3967 rte->perminfoindex - 1);
3968 if (perminfo->
relid != rte->relid)
3969 elog(
ERROR,
"permission info at index %u (with relid=%u) does not match provided RTE (with relid=%u)",
3970 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 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
Assert(PointerIsAligned(start, uint64))
const FormData_pg_attribute * SystemAttributeByName(const char *attname)
void CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind, int flags)
const FormData_pg_attribute * SystemAttributeDefinition(AttrNumber attno)
#define CHKATYPE_ANYRECORD
#define HeapTupleIsValid(tuple)
#define MaxTupleAttributeNumber
static void * GETSTRUCT(const HeapTupleData *tuple)
#define MaxHeapAttributeNumber
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * list_copy_tail(const List *oldlist, int nskip)
List * list_concat(List *list1, const List *list2)
List * list_copy(const List *oldlist)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
List * list_truncate(List *list, int new_size)
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Oid get_relname_relid(const char *relname, Oid relnamespace)
Alias * makeAlias(const char *aliasname, List *colnames)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
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 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)
void markNullableIfNeeded(ParseState *pstate, Var *var)
CommonTableExpr * scanNameSpaceForCTE(ParseState *pstate, const char *refname, Index *ctelevelsup)
static FuzzyAttrMatchState * searchRangeTableForCol(ParseState *pstate, const char *alias, const char *colname, int location)
void errorMissingColumn(ParseState *pstate, const char *relname, const char *colname, int location)
static int specialAttNum(const char *attname)
Node * colNameToVar(ParseState *pstate, const char *colname, bool localonly, int location)
static ParseNamespaceItem * buildNSItemFromTupleDesc(RangeTblEntry *rte, Index rtindex, RTEPermissionInfo *perminfo, TupleDesc tupdesc)
static ParseNamespaceItem * scanNameSpaceForRelid(ParseState *pstate, Oid relid, int location)
CommonTableExpr * GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte, int rtelevelsup)
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
Oid attnumCollationId(Relation rd, int attid)
static RangeTblEntry * searchRangeTableForRel(ParseState *pstate, RangeVar *relation)
static void expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset, int rtindex, int sublevels_up, VarReturningType returning_type, int location, bool include_dropped, List **colnames, List **colvars)
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
ParseNamespaceItem * addRangeTableEntryForENR(ParseState *pstate, RangeVar *rv, bool inFromCl)
void markVarForSelectPriv(ParseState *pstate, Var *var)
ParseNamespaceItem * addRangeTableEntry(ParseState *pstate, RangeVar *relation, Alias *alias, bool inh, bool inFromCl)
RowMarkClause * get_parse_rowmark(Query *qry, Index rtindex)
char * get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
static ParseNamespaceItem * scanNameSpaceForRefname(ParseState *pstate, const char *refname, int location)
void errorMissingRTE(ParseState *pstate, RangeVar *relation)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
static bool isFutureCTE(ParseState *pstate, const char *refname)
ParseNamespaceItem * addRangeTableEntryForTableFunc(ParseState *pstate, TableFunc *tf, Alias *alias, bool lateral, bool inFromCl)
List * expandNSItemVars(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location, List **colnames)
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)
Relation parserOpenTable(ParseState *pstate, const RangeVar *relation, int lockmode)
static ParseNamespaceItem * buildNSItemFromLists(RangeTblEntry *rte, Index rtindex, List *coltypes, List *coltypmods, List *colcollations)
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
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, VarReturningType returning_type, int location, bool include_dropped, List **colnames, List **colvars)
ParseNamespaceItem * GetNSItemByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
bool scanNameSpaceForENR(ParseState *pstate, const char *refname)
Node * scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, const char *colname, int location)
ParseNamespaceItem * addRangeTableEntryForFunction(ParseState *pstate, List *funcnames, List *funcexprs, List *coldeflists, RangeFunction *rangefunc, bool lateral, bool inFromCl)
bool isLockedRefname(ParseState *pstate, const char *refname)
Oid attnumTypeId(Relation rd, int attid)
RTEPermissionInfo * addRTEPermissionInfo(List **rteperminfos, RangeTblEntry *rte)
const NameData * attnumAttName(Relation rd, int attid)
ParseNamespaceItem * addRangeTableEntryForSubquery(ParseState *pstate, Query *subquery, Alias *alias, bool lateral, bool inFromCl)
static void expandRelation(Oid relid, Alias *eref, int rtindex, int sublevels_up, VarReturningType returning_type, int location, bool include_dropped, List **colnames, List **colvars)
ParseNamespaceItem * addRangeTableEntryForCTE(ParseState *pstate, CommonTableExpr *cte, Index levelsup, RangeVar *rv, bool inFromCl)
static bool rte_visible_if_qualified(ParseState *pstate, RangeTblEntry *rte)
ParseNamespaceItem * addRangeTableEntryForGroup(ParseState *pstate, List *groupClauses)
static void markRTEForSelectPriv(ParseState *pstate, int rtindex, AttrNumber col)
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)
List * expandNSItemAttrs(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, bool require_col_privs, int location)
ParseNamespaceItem * refnameNamespaceItem(ParseState *pstate, const char *schemaname, const char *refname, int location, int *sublevels_up)
RangeTblEntry * GetRTEByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
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 char * chooseScalarFunctionAlias(Node *funcexpr, char *funcname, Alias *alias, int nfuncs)
static ParseNamespaceItem * findNSItemForRTE(ParseState *pstate, RangeTblEntry *rte)
static void check_lateral_ref_ok(ParseState *pstate, ParseNamespaceItem *nsitem, int location)
ParseNamespaceItem * addRangeTableEntryForValues(ParseState *pstate, List *exprs, List *coltypes, List *coltypmods, List *colcollations, Alias *alias, bool lateral, bool inFromCl)
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 void * list_nth(const List *list, int n)
static ListCell * list_nth_cell(const List *list, int n)
static ListCell * list_head(const List *l)
#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)
VarReturningType p_varreturningtype
ParseNamespaceColumn * p_nscolumns
RTEPermissionInfo * p_perminfo
VarReturningType p_returning_type
ParseState * parentParseState
ParseNamespaceItem * p_target_nsitem
ParseExprKind p_expr_kind
bool p_locked_from_parent
VarReturningType varreturningtype
#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_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)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int 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)