提交 e720195a authored 作者: Noel Grandin's avatar Noel Grandin

Implement ILIKE operator for case-insensitive matching

上级 eed8f2ba
......@@ -1809,7 +1809,7 @@ compare { { { ALL | ANY | SOME } ( select ) } | operand }
| IS [ NOT ] [ DISTINCT FROM ] operand
| BETWEEN operand AND operand
| IN ( { select | expression [,...] } )
| [ NOT ] LIKE operand [ ESCAPE string ]
| [ NOT ] [ LIKE | ILIKE ] operand [ ESCAPE string ]
| [ NOT ] REGEXP operand
","
The right hand side of a condition.
......@@ -1826,6 +1826,8 @@ At most one escape character is allowed.
Each character that follows the escape character in the pattern needs to match exactly.
Patterns that end with an escape character are invalid and the expression returns NULL.
ILIKE does a case-insensitive compare.
When comparing with REGEXP, regular expression matching is used.
See Java ""Matcher.find"" for details.
","
......
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Implement ILIKE operator for case-insensitive matching
</li>
<li>Optimise LIKE queries for the common cases of '%Foo' and '%Foo%'
</li>
<li>Issue #387: H2 MSSQL Compatibility Mode - Support uniqueidentifier
......
......@@ -2148,6 +2148,18 @@ public class Parser {
}
recompileAlways = true;
r = new CompareLike(database, r, b, esc, false);
} else if (readIf("ILIKE")) {
Function function = Function.getFunction(database, "CAST");
function.setDataType(new Column("X", Value.STRING_IGNORECASE));
function.setParameter(0, r);
r = function;
Expression b = readConcat();
Expression esc = null;
if (readIf("ESCAPE")) {
esc = readConcat();
}
recompileAlways = true;
r = new CompareLike(database, r, b, esc, false);
} else if (readIf("REGEXP")) {
Expression b = readConcat();
r = new CompareLike(database, r, b, null, true);
......
......@@ -7378,6 +7378,17 @@ SELECT * FROM TEST WHERE NAME LIKE 'Hello%';
> 1 Hello
> rows: 1
SELECT * FROM TEST WHERE NAME ILIKE 'hello%';
> ID NAME
> -- -----
> 1 Hello
> rows: 1
SELECT * FROM TEST WHERE NAME ILIKE 'xxx%';
> ID NAME
> -- ----
> rows: 0
SELECT * FROM TEST WHERE NAME LIKE 'Wo%';
> ID NAME
> -- -----
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论