aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-09-26 02:16:40 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-09-26 02:16:40 +0000
commit3d8fd757326a4f5817069b07c5b1708282b02a30 (patch)
treec3a0a6e22be6b88ae1d1fe125ea03a89f5c55f31 /src
parente8e746de34d1f43a4b3936ff73630a70244cdc5f (diff)
downloadpostgresql-3d8fd757326a4f5817069b07c5b1708282b02a30.tar.gz
postgresql-3d8fd757326a4f5817069b07c5b1708282b02a30.zip
Make LIKE throw an error if the escape character is at the end of the pattern
(ie, has nothing to quote), rather than silently ignoring the character as has been our historical behavior. This is required by SQL spec and should help reduce the sort of user confusion seen in bug #4436. Per discussion. This is not so much a bug fix as a definitional change, and it could break existing applications; so not back-patched. It might deserve being mentioned as an incompatibility in the 8.4 release notes.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/like_match.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/backend/utils/adt/like_match.c b/src/backend/utils/adt/like_match.c
index 4a8f96c7d40..0f521bc91f4 100644
--- a/src/backend/utils/adt/like_match.c
+++ b/src/backend/utils/adt/like_match.c
@@ -1,13 +1,13 @@
/*-------------------------------------------------------------------------
*
* like_match.c
- * like expression handling internal code.
+ * LIKE pattern matching internal code.
*
- * This file is included by like.c four times, to provide natching code for
- * single-byte encodings, UTF8, and for other multi-byte encodings,
- * and case insensitive matches for single byte encodings.
- * UTF8 is a special case because we can use a much more efficient version
- * of NextChar than can be used for other multi-byte encodings.
+ * This file is included by like.c four times, to provide matching code for
+ * (1) single-byte encodings, (2) UTF8, (3) other multi-byte encodings,
+ * and (4) case insensitive matches in single byte encodings.
+ * (UTF8 is a special case because we can use a much more efficient version
+ * of NextChar than can be used for general multi-byte encodings.)
*
* Before the inclusion, we need to define following macros:
*
@@ -19,7 +19,7 @@
* Copyright (c) 1996-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.21 2008/03/01 03:26:34 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.22 2008/09/26 02:16:40 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -96,9 +96,14 @@ MatchText(char *t, int tlen, char *p, int plen)
{
if (*p == '\\')
{
- /* Next byte must match literally, whatever it is */
+ /* Next pattern byte must match literally, whatever it is */
NextByte(p, plen);
- if ((plen <= 0) || *p != *t)
+ /* ... and there had better be one, per SQL standard */
+ if (plen <= 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
+ errmsg("LIKE pattern must not end with escape character")));
+ if (*p != *t)
return LIKE_FALSE;
}
else if (*p == '%')