75#define MAX_FUZZY_DISTANCE 3
87 const char *colname,
int location,
88 int fuzzy_rte_penalty,
93 int rtindex,
int sublevels_up,
95 int location,
bool include_dropped,
98 int count,
int offset,
99 int rtindex,
int sublevels_up,
101 int location,
bool include_dropped,
135 const char *schemaname,
145 if (schemaname != NULL)
165 while (pstate != NULL)
225 (
errcode(ERRCODE_AMBIGUOUS_ALIAS),
226 errmsg(
"table reference \"%s\" is ambiguous",
267 rte->relid == relid &&
272 (
errcode(ERRCODE_AMBIGUOUS_ALIAS),
273 errmsg(
"table reference %u is ambiguous",
305 if (strcmp(cte->
ctename, refname) == 0)
307 *ctelevelsup = levelsup;
331 if (strcmp(cte->
ctename, refname) == 0)
366 const char *refname = relation->
relname;
370 Index ctelevelsup = 0;
413 strcmp(rte->
ctename, refname) == 0)
417 strcmp(rte->
enrname, refname) == 0)
419 if (strcmp(rte->eref->aliasname, refname) == 0)
447 foreach(l1, namespace1)
457 foreach(l2, namespace2)
465 if (strcmp(aliasname2, aliasname1) != 0)
469 rte1->relid != rte2->relid)
472 (
errcode(ERRCODE_DUPLICATE_ALIAS),
473 errmsg(
"table name \"%s\" specified more than once",
501 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
502 errmsg(
"invalid reference to FROM-clause entry for table \"%s\"",
506 errhint(
"There is an entry for table \"%s\", but it cannot be referenced from this part of the query.",
508 errdetail(
"The combining JOIN type must be INNER or LEFT for a LATERAL reference."),
524 while (sublevels_up-- > 0)
536 elog(
ERROR,
"nsitem not found (internal error)");
549 while (sublevels_up-- > 0)
572 while (levelsup-- > 0)
597 const char *actual,
const char *match,
int attnum)
603 if (fuzzy_rte_penalty > fuzzystate->
distance)
610 if (actual[0] ==
'\0')
614 matchlen = strlen(match);
626 if (columndistance > matchlen / 2)
633 columndistance += fuzzy_rte_penalty;
639 if (columndistance < fuzzystate->distance)
642 fuzzystate->
distance = columndistance;
647 else if (columndistance == fuzzystate->
distance)
650 if (fuzzystate->
rsecond != NULL)
659 fuzzystate->
rfirst = NULL;
662 else if (fuzzystate->
rfirst != NULL)
689 int sublevels_up,
const char *colname,
int location)
710 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
711 errmsg(
"system column \"%s\" reference in check constraint is invalid",
723 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
724 errmsg(
"cannot use system column \"%s\" in column generation expression",
734 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
735 errmsg(
"cannot use system column \"%s\" in MERGE WHEN condition",
748 (
errcode(ERRCODE_UNDEFINED_COLUMN),
749 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
773 sysatt->attcollation,
817 const char *colname,
int location,
818 int fuzzy_rte_penalty,
843 if (strcmp(attcolname, colname) == 0)
847 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
848 errmsg(
"column reference \"%s\" is ambiguous",
855 if (fuzzystate != NULL)
857 rte, attcolname, colname,
attnum);
873 rte->relkind != RELKIND_COMPOSITE_TYPE)
902 int sublevels_up = 0;
905 while (pstate != NULL)
929 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
930 errmsg(
"column reference \"%s\" is ambiguous",
938 if (result != NULL || localonly)
974 fuzzystate->
rfirst = NULL;
979 while (pstate != NULL)
986 int fuzzy_rte_penalty = 0;
1007 rte->eref->aliasname,
1008 strlen(rte->eref->aliasname),
1021 fuzzy_rte_penalty, fuzzystate);
1024 if (fuzzystate->
rexact1 == NULL)
1052 int rtindex = var->
varno;
1070 var->varnullingrels =
bms_union(var->varnullingrels, relids);
1112 elog(
ERROR,
"could not find JoinExpr for whole-row reference");
1123 int varno = ((
JoinExpr *)
j->larg)->rtindex;
1128 elog(
ERROR,
"unrecognized node type: %d",
1138 int varno = ((
JoinExpr *)
j->rarg)->rtindex;
1143 elog(
ERROR,
"unrecognized node type: %d",
1194 int maxattrs = tupdesc->
natts;
1218 for (varattno = 0; varattno < maxattrs; varattno++)
1223 if (attr->attisdropped)
1235 aliaslc =
lnext(aliaslist, aliaslc);
1250 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
1251 errmsg(
"table \"%s\" has %d columns available but %d columns specified",
1252 eref->
aliasname, maxattrs - numdropped, numaliases)));
1270 Alias *alias,
int nfuncs)
1290 if (nfuncs == 1 && alias)
1315 int maxattrs = tupdesc->
natts;
1325 for (varattno = 0; varattno < maxattrs; varattno++)
1330 if (attr->attisdropped)
1333 nscolumns[varattno].
p_varno = rtindex;
1334 nscolumns[varattno].
p_varattno = varattno + 1;
1335 nscolumns[varattno].
p_vartype = attr->atttypid;
1336 nscolumns[varattno].
p_vartypmod = attr->atttypmod;
1337 nscolumns[varattno].
p_varcollid = attr->attcollation;
1345 nsitem->
p_rte = rte;
1396 nscolumns[varattno].
p_varno = rtindex;
1397 nscolumns[varattno].
p_varattno = varattno + 1;
1409 nsitem->
p_rte = rte;
1447 errmsg(
"relation \"%s.%s\" does not exist",
1460 errmsg(
"relation \"%s\" does not exist",
1462 errdetail(
"There is a WITH item named \"%s\", but it cannot be referenced from this part of the query.",
1464 errhint(
"Use WITH RECURSIVE, or re-order the WITH items to remove forward references.")));
1468 errmsg(
"relation \"%s\" does not exist",
1521 rte->relkind = rel->
rd_rel->relkind;
1522 rte->rellockmode = lockmode;
1537 rte->lateral =
false;
1538 rte->inFromCl = inFromCl;
1606 rte->relkind = rel->
rd_rel->relkind;
1607 rte->rellockmode = lockmode;
1622 rte->lateral =
false;
1623 rte->inFromCl = inFromCl;
1681 coltypes = coltypmods = colcollations =
NIL;
1691 if (varattno > numaliases)
1695 attrname =
pstrdup(te->resname);
1705 if (varattno < numaliases)
1707 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
1708 errmsg(
"table \"%s\" has %d columns available but %d columns specified",
1709 eref->
aliasname, varattno, numaliases)));
1719 rte->lateral = lateral;
1720 rte->inFromCl = inFromCl;
1734 coltypes, coltypmods, colcollations);
1802 forthree(lc1, funcexprs, lc2, funcnames, lc3, coldeflists)
1813 rtfunc->funccolnames =
NIL;
1814 rtfunc->funccoltypes =
NIL;
1815 rtfunc->funccoltypmods =
NIL;
1816 rtfunc->funccolcollations =
NIL;
1817 rtfunc->funcparams = NULL;
1832 if (coldeflist !=
NIL)
1834 switch (functypclass)
1847 if (
exprType(funcexpr) == RECORDOID)
1849 (
errcode(ERRCODE_SYNTAX_ERROR),
1850 errmsg(
"a column definition list is redundant for a function with OUT parameters"),
1855 (
errcode(ERRCODE_SYNTAX_ERROR),
1856 errmsg(
"a column definition list is redundant for a function returning a named composite type"),
1862 (
errcode(ERRCODE_SYNTAX_ERROR),
1863 errmsg(
"a column definition list is only allowed for functions returning \"record\""),
1873 (
errcode(ERRCODE_SYNTAX_ERROR),
1874 errmsg(
"a column definition list is required for functions returning \"record\""),
1910 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1911 errmsg(
"column definition lists can have at most %d entries",
1917 foreach(col, coldeflist)
1928 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1929 errmsg(
"column \"%s\" cannot be declared SETOF",
1933 &attrtype, &attrtypmod);
1944 rtfunc->funccolnames =
lappend(rtfunc->funccolnames,
1946 rtfunc->funccoltypes =
lappend_oid(rtfunc->funccoltypes,
1948 rtfunc->funccoltypmods =
lappend_int(rtfunc->funccoltypmods,
1950 rtfunc->funccolcollations =
lappend_oid(rtfunc->funccolcollations,
1970 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1971 errmsg(
"function \"%s\" in FROM has unsupported return type %s",
1976 rtfunc->funccolcount = tupdesc->
natts;
1980 functupdescs[funcno] = tupdesc;
1981 totalatts += tupdesc->
natts;
1997 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
1998 errmsg(
"functions in FROM can return at most %d columns",
2006 for (
i = 0;
i < nfuncs;
i++)
2008 for (
j = 1;
j <= functupdescs[
i]->
natts;
j++)
2024 Assert(natts == totalatts);
2029 tupdesc = functupdescs[0];
2041 rte->lateral = lateral;
2042 rte->inFromCl = inFromCl;
2082 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2083 errmsg(
"functions in FROM can return at most %d columns",
2095 rte->coltypes = tf->coltypes;
2096 rte->coltypmods = tf->coltypmods;
2097 rte->colcollations = tf->colcollations;
2112 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2113 errmsg(
"%s function has %d columns available but %d columns specified",
2125 rte->lateral = lateral;
2126 rte->inFromCl = inFromCl;
2140 rte->coltypes, rte->coltypmods,
2141 rte->colcollations);
2155 List *colcollations,
2172 rte->coltypes = coltypes;
2173 rte->coltypmods = coltypmods;
2174 rte->colcollations = colcollations;
2182 while (numaliases < numcolumns)
2187 snprintf(attrname,
sizeof(attrname),
"column%d", numaliases);
2191 if (numcolumns < numaliases)
2193 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2194 errmsg(
"VALUES lists \"%s\" have %d columns available but %d columns specified",
2195 refname, numcolumns, numaliases)));
2205 rte->lateral = lateral;
2206 rte->inFromCl = inFromCl;
2220 rte->coltypes, rte->coltypmods,
2221 rte->colcollations);
2241 Alias *join_using_alias,
2258 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2259 errmsg(
"joins can have at most %d columns",
2266 rte->joinmergedcols = nummergedcols;
2267 rte->joinaliasvars = aliasvars;
2268 rte->joinleftcols = leftcols;
2269 rte->joinrightcols = rightcols;
2270 rte->join_using_alias = join_using_alias;
2283 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2284 errmsg(
"join expression \"%s\" has %d columns available but %d columns specified",
2295 rte->lateral =
false;
2296 rte->inFromCl = inFromCl;
2311 nsitem->
p_rte = rte;
2345 int n_dontexpand_columns = 0;
2356 Assert(cte->cterecursive || !rte->self_reference);
2358 if (!rte->self_reference)
2374 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2375 errmsg(
"WITH query \"%s\" does not have a RETURNING clause",
2380 rte->coltypes =
list_copy(cte->ctecoltypes);
2381 rte->coltypmods =
list_copy(cte->ctecoltypmods);
2382 rte->colcollations =
list_copy(cte->ctecolcollations);
2393 foreach(lc, cte->ctecolnames)
2396 if (varattno > numaliases)
2399 if (varattno < numaliases)
2401 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2402 errmsg(
"table \"%s\" has %d columns available but %d columns specified",
2403 refname, varattno, numaliases)));
2407 if (cte->search_clause)
2409 rte->eref->colnames =
lappend(rte->eref->colnames,
makeString(cte->search_clause->search_seq_column));
2410 if (cte->search_clause->search_breadth_first)
2411 rte->coltypes =
lappend_oid(rte->coltypes, RECORDOID);
2413 rte->coltypes =
lappend_oid(rte->coltypes, RECORDARRAYOID);
2414 rte->coltypmods =
lappend_int(rte->coltypmods, -1);
2417 n_dontexpand_columns += 1;
2420 if (cte->cycle_clause)
2422 rte->eref->colnames =
lappend(rte->eref->colnames,
makeString(cte->cycle_clause->cycle_mark_column));
2423 rte->coltypes =
lappend_oid(rte->coltypes, cte->cycle_clause->cycle_mark_type);
2424 rte->coltypmods =
lappend_int(rte->coltypmods, cte->cycle_clause->cycle_mark_typmod);
2425 rte->colcollations =
lappend_oid(rte->colcollations, cte->cycle_clause->cycle_mark_collation);
2427 rte->eref->colnames =
lappend(rte->eref->colnames,
makeString(cte->cycle_clause->cycle_path_column));
2428 rte->coltypes =
lappend_oid(rte->coltypes, RECORDARRAYOID);
2429 rte->coltypmods =
lappend_int(rte->coltypmods, -1);
2432 n_dontexpand_columns += 2;
2441 rte->lateral =
false;
2442 rte->inFromCl = inFromCl;
2456 rte->coltypes, rte->coltypmods,
2457 rte->colcollations);
2464 for (
int i = 0;
i < n_dontexpand_columns;
i++)
2527 rte->coltypes =
NIL;
2528 rte->coltypmods =
NIL;
2529 rte->colcollations =
NIL;
2530 for (attno = 1; attno <= tupdesc->
natts; ++attno)
2534 if (att->attisdropped)
2538 rte->coltypmods =
lappend_int(rte->coltypmods, 0);
2545 elog(
ERROR,
"atttypid is invalid for non-dropped column in \"%s\"",
2547 rte->coltypes =
lappend_oid(rte->coltypes, att->atttypid);
2548 rte->coltypmods =
lappend_int(rte->coltypmods, att->atttypmod);
2549 rte->colcollations =
lappend_oid(rte->colcollations,
2560 rte->lateral =
false;
2561 rte->inFromCl = inFromCl;
2604 coltypes = coltypmods = colcollations =
NIL;
2605 foreach(lc, groupClauses)
2608 char *colname = te->resname ?
pstrdup(te->resname) :
"?column?";
2623 rte->groupexprs = groupexprs;
2631 rte->lateral =
false;
2632 rte->inFromCl =
false;
2646 coltypes, coltypmods, colcollations);
2686 else if (refname != NULL)
2695 if (strcmp(refname, thisrel->
relname) == 0)
2712 bool addToRelNameSpace,
bool addToVarNameSpace)
2721 if (addToRelNameSpace || addToVarNameSpace)
2753 int location,
bool include_dropped,
2768 rtindex, sublevels_up, returning_type, location,
2769 include_dropped, colnames, colvars);
2796 elog(
ERROR,
"too few column names for subquery %s",
2797 rte->eref->aliasname);
2810 varnode =
makeVar(rtindex, varattno,
2818 *colvars =
lappend(*colvars, varnode);
2821 aliasp_item =
lnext(rte->eref->colnames, aliasp_item);
2839 if (rtfunc->funccolnames !=
NIL)
2852 rtfunc->funccolcount, atts_done,
2853 rtindex, sublevels_up,
2854 returning_type, location,
2855 include_dropped, colnames, colvars);
2861 *colnames =
lappend(*colnames,
2869 varnode =
makeVar(rtindex, atts_done + 1,
2877 *colvars =
lappend(*colvars, varnode);
2890 rtfunc->funccolcount);
2902 l2, rtfunc->funccoltypmods,
2903 l3, rtfunc->funccolcollations)
2919 *colvars =
lappend(*colvars, varnode);
2926 elog(
ERROR,
"function in FROM has unsupported return type");
2928 atts_done += rtfunc->funccolcount;
2935 *colnames =
lappend(*colnames,
2936 llast(rte->eref->colnames));
2948 *colvars =
lappend(*colvars, varnode);
2962 forboth(colname, rte->eref->colnames, aliasvar, rte->joinaliasvars)
2978 if (include_dropped)
2981 *colnames =
lappend(*colnames,
3002 *colnames =
lappend(*colnames,
3025 varnode =
makeVar(rtindex, varattno,
3033 *colvars =
lappend(*colvars, varnode);
3051 lcm, rte->coltypmods,
3052 lcc, rte->colcollations)
3067 *colnames =
lappend(*colnames,
3070 else if (include_dropped)
3071 *colnames =
lappend(*colnames,
3074 aliasp_item =
lnext(rte->eref->colnames, aliasp_item);
3083 varnode =
makeVar(rtindex, varattno,
3084 coltype, coltypmod, colcoll,
3089 *colvars =
lappend(*colvars, varnode);
3091 else if (include_dropped)
3120 int location,
bool include_dropped,
3128 rtindex, sublevels_up, returning_type,
3129 location, include_dropped,
3145 int rtindex,
int sublevels_up,
3147 int location,
bool include_dropped,
3156 Assert(count <= tupdesc->natts);
3157 for (varattno = 0; varattno < count; varattno++)
3161 if (attr->attisdropped)
3163 if (include_dropped)
3203 varnode =
makeVar(rtindex, varattno + offset + 1,
3204 attr->atttypid, attr->atttypmod,
3210 *colvars =
lappend(*colvars, varnode);
3228 int sublevels_up,
int location,
3241 const char *colname =
strVal(colnameval);
3248 else if (colname[0])
3268 result =
lappend(result, var);
3270 *colnames =
lappend(*colnames, colnameval);
3293 int sublevels_up,
bool require_col_privs,
int location)
3315 Assert(perminfo != NULL);
3329 te_list =
lappend(te_list, te);
3331 if (require_col_privs)
3386 elog(
ERROR,
"invalid attnum %d for rangetable entry %s",
3387 attnum, rte->eref->aliasname);
3414 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
3417 result = att_tup->attisdropped;
3458 result = (aliasvar == NULL);
3478 if (
attnum > atts_done &&
3479 attnum <= atts_done + rtfunc->funccolcount)
3484 if (rtfunc->funccolnames !=
NIL)
3498 return att_tup->attisdropped;
3503 atts_done += rtfunc->funccolcount;
3512 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3513 errmsg(
"column %d of relation \"%s\" does not exist",
3515 rte->eref->aliasname)));
3522 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3523 errmsg(
"column %d of relation \"%s\" does not exist",
3525 rte->eref->aliasname)));
3553 if (tle->
resno == resno)
3573 if (rc->
rti == rtindex)
3626 return sysatt->attnum;
3646 return &sysatt->attname;
3649 elog(
ERROR,
"invalid attribute number %d", attid);
3668 return sysatt->atttypid;
3671 elog(
ERROR,
"invalid attribute number %d", attid);
3689 elog(
ERROR,
"invalid attribute number %d", attid);
3703 const char *badAlias = NULL;
3722 if (rte && rte->alias &&
3723 strcmp(rte->eref->aliasname, relation->
relname) != 0)
3731 if (nsitem && nsitem->
p_rte == rte)
3732 badAlias = rte->eref->aliasname;
3739 errmsg(
"invalid reference to FROM-clause entry for table \"%s\"",
3741 errhint(
"Perhaps you meant to reference the table alias \"%s\".",
3748 errmsg(
"invalid reference to FROM-clause entry for table \"%s\"",
3750 errdetail(
"There is an entry for table \"%s\", but it cannot be referenced from this part of the query.",
3751 rte->eref->aliasname),
3753 errhint(
"To reference that table, you must mark this subquery with LATERAL.") : 0,
3759 errmsg(
"missing FROM-clause entry for table \"%s\"",
3772 const char *
relname,
const char *colname,
int location)
3795 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3798 errmsg(
"column \"%s\" does not exist", colname),
3799 errdetail(
"There are columns named \"%s\", but they are in tables that cannot be referenced from this part of the query.",
3805 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3808 errmsg(
"column \"%s\" does not exist", colname),
3809 errdetail(
"There is a column named \"%s\" in table \"%s\", but it cannot be referenced from this part of the query.",
3810 colname,
state->rexact1->eref->aliasname),
3812 errhint(
"To reference that column, you must mark this subquery with LATERAL.") :
3814 errhint(
"To reference that column, you must use a table-qualified name.") : 0,
3818 if (!
state->rsecond)
3823 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3826 errmsg(
"column \"%s\" does not exist", colname),
3830 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3833 errmsg(
"column \"%s\" does not exist", colname),
3834 errhint(
"Perhaps you meant to reference the column \"%s.%s\".",
3835 state->rfirst->eref->aliasname,
3837 state->first - 1))),
3844 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3847 errmsg(
"column \"%s\" does not exist", colname),
3848 errhint(
"Perhaps you meant to reference the column \"%s.%s\" or the column \"%s.%s\".",
3849 state->rfirst->eref->aliasname,
3852 state->rsecond->eref->aliasname,
3854 state->second - 1))),
3866 while (pstate != NULL)
3874 if (nsitem->
p_rte == rte)
3946 foreach(rtable, query->
rtable)
3953 char relpersistence = rel->
rd_rel->relpersistence;
3956 if (relpersistence == RELPERSISTENCE_TEMP)
3985 Assert(rte->perminfoindex == 0);
3989 perminfo->
relid = rte->relid;
3990 perminfo->
inh = rte->
inh;
3993 *rteperminfos =
lappend(*rteperminfos, perminfo);
4013 if (rte->perminfoindex == 0 ||
4015 elog(
ERROR,
"invalid perminfoindex %u in RTE with relid %u",
4016 rte->perminfoindex, rte->relid);
4018 rte->perminfoindex - 1);
4019 if (perminfo->
relid != rte->relid)
4020 elog(
ERROR,
"permission info at index %u (with relid=%u) does not match provided RTE (with relid=%u)",
4021 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 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)
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)
bool isQueryUsingTempRelation(Query *query)
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)
static bool isQueryUsingTempRelation_walker(Node *node, void *context)
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_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)
static FormData_pg_attribute * TupleDescAttr(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)