aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/oracle_compat.c
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2025-01-24 14:56:22 -0800
committerJeff Davis <jdavis@postgresql.org>2025-01-24 14:56:22 -0800
commitbfc5992069cf00b189af83d96a83ae5ebb65e938 (patch)
tree94332f38e12deb4a6dcfdc011c42848069190ec5 /src/backend/utils/adt/oracle_compat.c
parentf15538cd27d4eeb7d665263a3d7b5700362d7eb0 (diff)
downloadpostgresql-bfc5992069cf00b189af83d96a83ae5ebb65e938.tar.gz
postgresql-bfc5992069cf00b189af83d96a83ae5ebb65e938.zip
Add SQL function CASEFOLD().
Useful for caseless matching. Similar to LOWER(), but avoids edge-case problems with using LOWER() for caseless matching. For collations that support it, CASEFOLD() handles characters with more than two case variations or multi-character case variations. Some characters may fold to uppercase. The results of case folding are also more stable across Unicode versions than LOWER() or UPPER(). Discussion: https://postgr.es/m/a1886ddfcd8f60cb3e905c93009b646b4cfb74c5.camel%40j-davis.com Reviewed-by: Ian Lawrence Barwick
Diffstat (limited to 'src/backend/utils/adt/oracle_compat.c')
-rw-r--r--src/backend/utils/adt/oracle_compat.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c
index 2cba7cd1621..a24a2d208fb 100644
--- a/src/backend/utils/adt/oracle_compat.c
+++ b/src/backend/utils/adt/oracle_compat.c
@@ -126,6 +126,22 @@ initcap(PG_FUNCTION_ARGS)
PG_RETURN_TEXT_P(result);
}
+Datum
+casefold(PG_FUNCTION_ARGS)
+{
+ text *in_string = PG_GETARG_TEXT_PP(0);
+ char *out_string;
+ text *result;
+
+ out_string = str_casefold(VARDATA_ANY(in_string),
+ VARSIZE_ANY_EXHDR(in_string),
+ PG_GET_COLLATION());
+ result = cstring_to_text(out_string);
+ pfree(out_string);
+
+ PG_RETURN_TEXT_P(result);
+}
+
/********************************************************************
*