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

Commit 3d8fd75

Browse files
committed
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.
1 parent e8e746d commit 3d8fd75

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/backend/utils/adt/like_match.c

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*-------------------------------------------------------------------------
22
*
33
* like_match.c
4-
* like expression handling internal code.
4+
* LIKE pattern matching internal code.
55
*
6-
* This file is included by like.c four times, to provide natching code for
7-
* single-byte encodings, UTF8, and for other multi-byte encodings,
8-
* and case insensitive matches for single byte encodings.
9-
* UTF8 is a special case because we can use a much more efficient version
10-
* of NextChar than can be used for other multi-byte encodings.
6+
* This file is included by like.c four times, to provide matching code for
7+
* (1) single-byte encodings, (2) UTF8, (3) other multi-byte encodings,
8+
* and (4) case insensitive matches in single byte encodings.
9+
* (UTF8 is a special case because we can use a much more efficient version
10+
* of NextChar than can be used for general multi-byte encodings.)
1111
*
1212
* Before the inclusion, we need to define following macros:
1313
*
@@ -19,7 +19,7 @@
1919
* Copyright (c) 1996-2008, PostgreSQL Global Development Group
2020
*
2121
* IDENTIFICATION
22-
* $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.21 2008/03/01 03:26:34 tgl Exp $
22+
* $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.22 2008/09/26 02:16:40 tgl Exp $
2323
*
2424
*-------------------------------------------------------------------------
2525
*/
@@ -96,9 +96,14 @@ MatchText(char *t, int tlen, char *p, int plen)
9696
{
9797
if (*p == '\\')
9898
{
99-
/* Next byte must match literally, whatever it is */
99+
/* Next pattern byte must match literally, whatever it is */
100100
NextByte(p, plen);
101-
if ((plen <= 0) || *p != *t)
101+
/* ... and there had better be one, per SQL standard */
102+
if (plen <= 0)
103+
ereport(ERROR,
104+
(errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
105+
errmsg("LIKE pattern must not end with escape character")));
106+
if (*p != *t)
102107
return LIKE_FALSE;
103108
}
104109
else if (*p == '%')

0 commit comments

Comments
 (0)