diff options
author | Teodor Sigaev <teodor@sigaev.ru> | 2016-03-18 12:26:27 +0300 |
---|---|---|
committer | Teodor Sigaev <teodor@sigaev.ru> | 2016-03-18 12:26:27 +0300 |
commit | aa698d753566f68bdd54881d30b1a515b0327b0e (patch) | |
tree | 9beca35f1faacd6cffb0bbb27dc13b2f191766c2 | |
parent | 696684d878747a1a5cfae01887404629c40c09dd (diff) | |
download | postgresql-aa698d753566f68bdd54881d30b1a515b0327b0e.tar.gz postgresql-aa698d753566f68bdd54881d30b1a515b0327b0e.zip |
pg_trgm's set_limit() now uses SetConfigOption()
Deprecated set_limit() is modified to use SetConfigOption() to set
similarity_threshold which is actually an instance of
pg_trgm.similarity_threshold GUC variable. Previous coding directly sets
similarity_threshold what could cause an inconsistency between states of
actual variable and GUC representation.
Per gripe from Tom Lane
-rw-r--r-- | contrib/pg_trgm/trgm_op.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/contrib/pg_trgm/trgm_op.c b/contrib/pg_trgm/trgm_op.c index eaf20e45159..3ca6e5e951e 100644 --- a/contrib/pg_trgm/trgm_op.c +++ b/contrib/pg_trgm/trgm_op.c @@ -9,6 +9,7 @@ #include "catalog/pg_type.h" #include "tsearch/ts_locale.h" +#include "utils/lsyscache.h" #include "utils/memutils.h" #include "utils/pg_crc.h" @@ -80,12 +81,17 @@ Datum set_limit(PG_FUNCTION_ARGS) { float4 nlimit = PG_GETARG_FLOAT4(0); + char *nlimit_str; + Oid func_out_oid; + bool is_varlena; + + getTypeOutputInfo(FLOAT4OID, &func_out_oid, &is_varlena); + + nlimit_str = OidOutputFunctionCall(func_out_oid, Float4GetDatum(nlimit)); + + SetConfigOption("pg_trgm.similarity_threshold", nlimit_str, + PGC_USERSET, PGC_S_SESSION); - if (nlimit < 0 || nlimit > 1.0) - ereport(ERROR, - (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("wrong threshold, should be between 0 and 1"))); - similarity_threshold = nlimit; PG_RETURN_FLOAT4(similarity_threshold); } |