Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3d8fd75

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 hasbeen our historical behavior. This is required by SQL spec and should helpreduce 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 breakexisting applications; so not back-patched. It might deserve being mentionedas an incompatibility in the 8.4 release notes.
1 parente8e746d commit3d8fd75

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

‎src/backend/utils/adt/like_match.c

Lines changed: 14 additions & 9 deletions
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 providenatching code for
7-
* single-byte encodings, UTF8,and for other multi-byte encodings,
8-
* and case insensitive matchesfor 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 forother multi-byte encodings.
6+
* This file is included by like.c four times, to providematching code for
7+
*(1)single-byte encodings,(2)UTF8,(3) other multi-byte encodings,
8+
* and(4)case insensitive matchesin 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 forgeneral 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+
/* Nextpatternbyte 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
returnLIKE_FALSE;
103108
}
104109
elseif (*p=='%')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp