Skip to content

Commit 88b5aa8

Browse files
committed
PostgresSQL regular expression case sensitive match
1 parent dc1aeb7 commit 88b5aa8

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
4545
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
4646
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
47+
import net.sf.jsqlparser.expression.operators.relational.RegExpCaseSensitiveMatch;
4748
import net.sf.jsqlparser.schema.Column;
4849
import net.sf.jsqlparser.statement.select.SubSelect;
4950

@@ -140,4 +141,6 @@ public interface ExpressionVisitor {
140141
void visit(IntervalExpression iexpr);
141142

142143
void visit(OracleHierarchicalExpression oexpr);
144+
145+
void visit(RegExpCaseSensitiveMatch rexpr);
143146
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2013 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.expression.operators.relational;
23+
24+
import net.sf.jsqlparser.expression.BinaryExpression;
25+
import net.sf.jsqlparser.expression.ExpressionVisitor;
26+
27+
public class RegExpCaseSensitiveMatch extends BinaryExpression {
28+
29+
@Override
30+
public void accept(ExpressionVisitor expressionVisitor) {
31+
expressionVisitor.visit(this);
32+
}
33+
34+
@Override
35+
public String getStringExpression() {
36+
return "~";
37+
}
38+
}

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
7474
import net.sf.jsqlparser.expression.operators.relational.MultiExpressionList;
7575
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
76+
import net.sf.jsqlparser.expression.operators.relational.RegExpCaseSensitiveMatch;
7677
import net.sf.jsqlparser.schema.Column;
7778
import net.sf.jsqlparser.schema.Table;
7879
import net.sf.jsqlparser.statement.delete.Delete;
@@ -506,4 +507,9 @@ public void visit(JdbcNamedParameter jdbcNamedParameter) {
506507
@Override
507508
public void visit(OracleHierarchicalExpression oexpr) {
508509
}
510+
511+
@Override
512+
public void visit(RegExpCaseSensitiveMatch rexpr) {
513+
visitBinaryExpression(rexpr);
514+
}
509515
}

src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,9 @@ public void visit(JdbcNamedParameter jdbcNamedParameter) {
487487
public void visit(OracleHierarchicalExpression oexpr) {
488488
buffer.append(oexpr.toString());
489489
}
490+
491+
@Override
492+
public void visit(RegExpCaseSensitiveMatch rexpr) {
493+
visitBinaryExpression(rexpr, " ~ ");
494+
}
490495
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
9898
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
9999
import net.sf.jsqlparser.expression.operators.relational.GreaterThan;
100100
import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals;
101+
import net.sf.jsqlparser.expression.operators.relational.RegExpCaseSensitiveMatch;
101102
import net.sf.jsqlparser.expression.operators.relational.InExpression;
102103
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
103104
import net.sf.jsqlparser.expression.operators.relational.ItemsList;
@@ -1333,6 +1334,7 @@ Expression RegularCondition():
13331334
| "<=" { result = new MinorThanEquals(); }
13341335
| ("<>" | "!=") { result = new NotEqualsTo(); }
13351336
| "@@" { result = new Matches(); }
1337+
| "~" { result = new RegExpCaseSensitiveMatch(); }
13361338
)
13371339
rightExpression=ComparisonItem()
13381340

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,4 +1148,9 @@ public void testOracleHierarchicalQuery3() throws JSQLParserException {
11481148
String stmt= "SELECT last_name, employee_id, manager_id, LEVEL FROM employees START WITH employee_id = 100 CONNECT BY PRIOR employee_id = manager_id ORDER SIBLINGS BY last_name";
11491149
assertSqlCanBeParsedAndDeparsed(stmt);
11501150
}
1151+
1152+
public void testPostgreSQLRegExpCaseSensitiveMatch() throws JSQLParserException {
1153+
String stmt= "SELECT a, b FROM foo WHERE a ~ '[help].*'";
1154+
assertSqlCanBeParsedAndDeparsed(stmt);
1155+
}
11511156
}

0 commit comments

Comments
 (0)