Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aa698d7

Browse files
committed
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
1 parent 696684d commit aa698d7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

contrib/pg_trgm/trgm_op.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "catalog/pg_type.h"
1111
#include "tsearch/ts_locale.h"
12+
#include "utils/lsyscache.h"
1213
#include "utils/memutils.h"
1314
#include "utils/pg_crc.h"
1415

@@ -80,12 +81,17 @@ Datum
8081
set_limit(PG_FUNCTION_ARGS)
8182
{
8283
float4 nlimit = PG_GETARG_FLOAT4(0);
84+
char *nlimit_str;
85+
Oid func_out_oid;
86+
bool is_varlena;
87+
88+
getTypeOutputInfo(FLOAT4OID, &func_out_oid, &is_varlena);
89+
90+
nlimit_str = OidOutputFunctionCall(func_out_oid, Float4GetDatum(nlimit));
91+
92+
SetConfigOption("pg_trgm.similarity_threshold", nlimit_str,
93+
PGC_USERSET, PGC_S_SESSION);
8394

84-
if (nlimit < 0 || nlimit > 1.0)
85-
ereport(ERROR,
86-
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
87-
errmsg("wrong threshold, should be between 0 and 1")));
88-
similarity_threshold = nlimit;
8995
PG_RETURN_FLOAT4(similarity_threshold);
9096
}
9197

0 commit comments

Comments
 (0)