aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/regexp.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-10-10 03:50:15 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-10-10 03:50:15 +0000
commit05d249717d652f0b16960d8a58611e222f1f907b (patch)
treef5999862b949fc1c991d3d7e2ff51ed170656de1 /src/backend/utils/adt/regexp.c
parent8a5849b7ff24c637a1140c26fc171e45c9142005 (diff)
downloadpostgresql-05d249717d652f0b16960d8a58611e222f1f907b.tar.gz
postgresql-05d249717d652f0b16960d8a58611e222f1f907b.zip
Improve similar_escape() in two different ways:
* Stop escaping ? and {. As of SQL:2008, SIMILAR TO is defined to have POSIX-compatible interpretation of ? as well as {m,n} and related constructs, so we should allow these things through to our regex engine. * Escape ^ and $. It appears that our regex engine will treat ^^ at the beginning of the string the same as ^, and similarly for $$ at the end of the string, which meant that SIMILAR TO was effectively ignoring ^ at the start of the pattern and $ at the end. Since these are not supposed to be metacharacters, this is a bug. The second part of this is arguably a back-patchable bug fix, but I'm hesitant to do that because it might break applications that are expecting something like "col SIMILAR TO '^foo$'" to work like a POSIX pattern. Seems safer to only change it at a major version boundary. Per discussion of an example from Doug Gorley.
Diffstat (limited to 'src/backend/utils/adt/regexp.c')
-rw-r--r--src/backend/utils/adt/regexp.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c
index e4e3c776658..118d42d2a0a 100644
--- a/src/backend/utils/adt/regexp.c
+++ b/src/backend/utils/adt/regexp.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.82 2009/06/11 14:49:04 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.83 2009/10/10 03:50:15 tgl Exp $
*
* Alistair Crooks added the code for the regex caching
* agc - cached the regular expressions used - there's a good chance
@@ -639,7 +639,7 @@ textregexreplace(PG_FUNCTION_ARGS)
/*
* similar_escape()
- * Convert a SQL99 regexp pattern to POSIX style, so it can be used by
+ * Convert a SQL:2008 regexp pattern to POSIX style, so it can be used by
* our regexp engine.
*/
Datum
@@ -740,8 +740,8 @@ similar_escape(PG_FUNCTION_ARGS)
}
else if (pchar == '_')
*r++ = '.';
- else if (pchar == '\\' || pchar == '.' || pchar == '?' ||
- pchar == '{')
+ else if (pchar == '\\' || pchar == '.' ||
+ pchar == '^' || pchar == '$')
{
*r++ = '\\';
*r++ = pchar;