diff options
author | Robert Haas <rhaas@postgresql.org> | 2015-03-11 10:44:04 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2015-03-11 10:44:04 -0400 |
commit | e529cd4ffa605c6f14f1391af5559b3a44da0336 (patch) | |
tree | edc9c0a16e48514e4f6570e2ecee56fff29e4ea6 /src/backend/utils | |
parent | bbfd7edae5aa5ad5553d3c7e102f2e450d4380d4 (diff) |
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/backend/utils')
-rw-r--r-- | src/backend/utils/adt/levenshtein.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/backend/utils/adt/levenshtein.c b/src/backend/utils/adt/levenshtein.c index 3669adc18a0..f6e2ca6452a 100644 --- a/src/backend/utils/adt/levenshtein.c +++ b/src/backend/utils/adt/levenshtein.c @@ -95,6 +95,15 @@ varstr_levenshtein(const char *source, int slen, const char *target, int tlen, #define STOP_COLUMN m #endif + /* + * A common use for Levenshtein distance is to match attributes when building + * diagnostic, user-visible messages. Restrict the size of + * MAX_LEVENSHTEIN_STRLEN at compile time so that this is guaranteed to + * work. + */ + StaticAssertStmt(NAMEDATALEN <= MAX_LEVENSHTEIN_STRLEN, + "Levenshtein hinting mechanism restricts NAMEDATALEN"); + m = pg_mbstrlen_with_len(source, slen); n = pg_mbstrlen_with_len(target, tlen); |