Skip to content

Commit 33f4f66

Browse files
author
Jonathan Burnhams
committed
Added regexp_like support
1 parent 43fe8ca commit 33f4f66

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
193193
| <K_NULL:"NULL">
194194
| <K_LIKE:"LIKE">
195195
| <K_REGEXP:"REGEXP">
196+
| <K_REGEXP_LIKE:"REGEXP_LIKE">
196197
| <K_DROP:"DROP">
197198
| <K_JOIN:"JOIN">
198199
| <K_LEFT:"LEFT">
@@ -1283,11 +1284,27 @@ Expression Condition():
12831284
}
12841285
{
12851286
(LOOKAHEAD(SQLCondition()) result=SQLCondition()
1286-
| result=RegularCondition())
1287+
| result=FunctionCondition()
1288+
| result=RegularCondition()
1289+
)
12871290

12881291
{ return result; }
12891292
}
12901293

1294+
Expression FunctionCondition():
1295+
{
1296+
Function result;
1297+
ExpressionList parameters;
1298+
}
1299+
{
1300+
<K_REGEXP_LIKE> { result = new Function(); result.setName("REGEXP_LIKE"); }
1301+
"("
1302+
parameters=SimpleExpressionList() { result.setParameters(parameters); }
1303+
")"
1304+
1305+
{ return result; }
1306+
}
1307+
12911308
Expression RegularCondition():
12921309
{
12931310
Expression result = null;

src/test/java/net/sf/jsqlparser/test/select/SelectTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,4 +1022,14 @@ public void testPivotXml3() throws JSQLParserException {
10221022
assertSqlCanBeParsedAndDeparsed(stmt);
10231023
}
10241024

1025+
public void testRegexpLike1() throws JSQLParserException {
1026+
String stmt = "SELECT * FROM mytable WHERE REGEXP_LIKE(first_name, '^Ste(v|ph)en$')";
1027+
assertSqlCanBeParsedAndDeparsed(stmt);
1028+
}
1029+
1030+
public void testRegexpLike2() throws JSQLParserException {
1031+
String stmt = "SELECT CASE WHEN REGEXP_LIKE(first_name, '^Ste(v|ph)en$') THEN 1 ELSE 2 END FROM mytable";
1032+
assertSqlCanBeParsedAndDeparsed(stmt);
1033+
}
1034+
10251035
}

0 commit comments

Comments
 (0)