diff options
Diffstat (limited to 'contrib/postgres_fdw/option.c')
-rw-r--r-- | contrib/postgres_fdw/option.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c index 95dde056eba..fa80ee2a55e 100644 --- a/contrib/postgres_fdw/option.c +++ b/contrib/postgres_fdw/option.c @@ -90,26 +90,31 @@ postgres_fdw_validator(PG_FUNCTION_ARGS) { /* * Unknown option specified, complain about it. Provide a hint - * with list of valid options for the object. + * with a valid option that looks similar, if there is one. */ PgFdwOption *opt; - StringInfoData buf; + const char *closest_match; + ClosestMatchState match_state; + bool has_valid_options = false; - initStringInfo(&buf); + initClosestMatch(&match_state, def->defname, 4); for (opt = postgres_fdw_options; opt->keyword; opt++) { if (catalog == opt->optcontext) - appendStringInfo(&buf, "%s%s", (buf.len > 0) ? ", " : "", - opt->keyword); + { + has_valid_options = true; + updateClosestMatch(&match_state, opt->keyword); + } } + closest_match = getClosestMatch(&match_state); ereport(ERROR, (errcode(ERRCODE_FDW_INVALID_OPTION_NAME), errmsg("invalid option \"%s\"", def->defname), - buf.len > 0 - ? errhint("Valid options in this context are: %s", - buf.data) - : errhint("There are no valid options in this context."))); + has_valid_options ? closest_match ? + errhint("Perhaps you meant the option \"%s\".", + closest_match) : 0 : + errhint("There are no valid options in this context."))); } /* |