aboutsummaryrefslogtreecommitdiff
path: root/src/include/parser/parse_relation.h
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2015-03-11 10:44:04 -0400
committerRobert Haas <rhaas@postgresql.org>2015-03-11 10:44:04 -0400
commite529cd4ffa605c6f14f1391af5559b3a44da0336 (patch)
treeedc9c0a16e48514e4f6570e2ecee56fff29e4ea6 /src/include/parser/parse_relation.h
parentbbfd7edae5aa5ad5553d3c7e102f2e450d4380d4 (diff)
downloadpostgresql-e529cd4ffa605c6f14f1391af5559b3a44da0336.tar.gz
postgresql-e529cd4ffa605c6f14f1391af5559b3a44da0336.zip
Suggest to the user the column they may have meant to reference.
Error messages informing the user that no such column exists can sometimes provoke a perplexed response. This often happens due to a subtle typo in the column name or, perhaps less likely, in the alias name. To speed discovery of what the real issue is in such cases, we'll now search the range table for approximate matches. If there are one or two such matches that are good enough to think that they might be what the user intended to type, and better than all other approximate matches, we'll issue a hint suggesting that the user might have intended to reference those columns. Peter Geoghegan and Robert Haas
Diffstat (limited to 'src/include/parser/parse_relation.h')
-rw-r--r--src/include/parser/parse_relation.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/include/parser/parse_relation.h b/src/include/parser/parse_relation.h
index fc0a2577f31..9dc0d5846b0 100644
--- a/src/include/parser/parse_relation.h
+++ b/src/include/parser/parse_relation.h
@@ -16,6 +16,24 @@
#include "parser/parse_node.h"
+
+/*
+ * Support for fuzzily matching column.
+ *
+ * This is for building diagnostic messages, where non-exact matching
+ * attributes are suggested to the user. The struct's fields may be facets of
+ * a particular RTE, or of an entire range table, depending on context.
+ */
+typedef struct
+{
+ int distance; /* Weighted distance (lowest so far) */
+ RangeTblEntry *rfirst; /* RTE of first */
+ AttrNumber first; /* Closest attribute so far */
+ RangeTblEntry *rsecond; /* RTE of second */
+ AttrNumber second; /* Second closest attribute so far */
+} FuzzyAttrMatchState;
+
+
extern RangeTblEntry *refnameRangeTblEntry(ParseState *pstate,
const char *schemaname,
const char *refname,
@@ -35,7 +53,8 @@ extern RangeTblEntry *GetRTEByRangeTablePosn(ParseState *pstate,
extern CommonTableExpr *GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte,
int rtelevelsup);
extern Node *scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte,
- char *colname, int location);
+ char *colname, int location,
+ int fuzzy_rte_penalty, FuzzyAttrMatchState *fuzzystate);
extern Node *colNameToVar(ParseState *pstate, char *colname, bool localonly,
int location);
extern void markVarForSelectPriv(ParseState *pstate, Var *var,