File tree Expand file tree Collapse file tree 4 files changed +17
-9
lines changed
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/statement/select Expand file tree Collapse file tree 4 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 1717public class TimezoneExpression extends ASTNodeAccessImpl implements Expression {
1818
1919 private Expression leftExpression ;
20- private ArrayList <String > timezoneExpressions = new ArrayList <>();
20+ private ArrayList <Expression > timezoneExpressions = new ArrayList <>();
2121
2222 public Expression getLeftExpression () {
2323 return leftExpression ;
@@ -32,19 +32,19 @@ public void accept(ExpressionVisitor expressionVisitor) {
3232 expressionVisitor .visit (this );
3333 }
3434
35- public List <String > getTimezoneExpressions () {
35+ public List <Expression > getTimezoneExpressions () {
3636 return timezoneExpressions ;
3737 }
3838
39- public void addTimezoneExpression (String timezoneExpr ) {
39+ public void addTimezoneExpression (Expression timezoneExpr ) {
4040 this .timezoneExpressions .add (timezoneExpr );
4141 }
4242
4343 @ Override
4444 public String toString () {
4545 String returnValue = getLeftExpression ().toString ();
46- for (String expr : timezoneExpressions ) {
47- returnValue += " AT TIME ZONE " + expr ;
46+ for (Expression expr : timezoneExpressions ) {
47+ returnValue += " AT TIME ZONE " + expr . toString () ;
4848 }
4949
5050 return returnValue ;
Original file line number Diff line number Diff line change @@ -924,8 +924,9 @@ public void visit(XMLSerializeExpr expr) {
924924 public void visit (TimezoneExpression var ) {
925925 var .getLeftExpression ().accept (this );
926926
927- for (String expr : var .getTimezoneExpressions ()) {
928- buffer .append (" AT TIME ZONE " + expr );
927+ for (Expression expr : var .getTimezoneExpressions ()) {
928+ buffer .append (" AT TIME ZONE " );
929+ expr .accept (this );
929930 }
930931 }
931932
Original file line number Diff line number Diff line change @@ -3638,6 +3638,7 @@ Expression PrimaryExpression() #PrimaryExpression:
36383638 Expression retval = null;
36393639 CastExpression castExpr = null;
36403640 TimezoneExpression timezoneExpr = null;
3641+ Expression timezoneRightExpr = null;
36413642 Token token = null;
36423643 Token sign = null;
36433644 String tmp = "";
@@ -3762,11 +3763,11 @@ Expression PrimaryExpression() #PrimaryExpression:
37623763 retval=castExpr;
37633764 } )*
37643765
3765- ( <K_AT> <K_DATETIMELITERAL> <K_ZONE> token=<S_CHAR_LITERAL> {
3766+ ( <K_AT> <K_DATETIMELITERAL> <K_ZONE> timezoneRightExpr=PrimaryExpression() {
37663767 if (timezoneExpr == null)
37673768 timezoneExpr = new TimezoneExpression();
37683769
3769- timezoneExpr.addTimezoneExpression(token.image );
3770+ timezoneExpr.addTimezoneExpression(timezoneRightExpr );
37703771 } )*
37713772
37723773 {
Original file line number Diff line number Diff line change @@ -884,6 +884,12 @@ public void testTimezoneExpressionWithTwoTransformations() throws JSQLParserExce
884884 assertSqlCanBeParsedAndDeparsed (stmt );
885885 }
886886
887+ @ Test
888+ public void testTimezoneExpressionWithColumnBasedTimezone () throws JSQLParserException {
889+ String stmt = "SELECT 1 FROM tbl WHERE col AT TIME ZONE timezone_col < '2021-11-05 00:00:35'::date + INTERVAL '1 day' * 0" ;
890+ assertSqlCanBeParsedAndDeparsed (stmt );
891+ }
892+
887893 @ Test
888894 public void testUnionWithOrderByAndLimitAndNoBrackets () throws JSQLParserException {
889895 String stmt = "SELECT id FROM table1 UNION SELECT id FROM table2 ORDER BY id ASC LIMIT 55" ;
You can’t perform that action at this time.
0 commit comments