|
9 | 9 | import net.sf.jsqlparser.expression.DoubleValue; |
10 | 10 | import net.sf.jsqlparser.expression.Expression; |
11 | 11 | import net.sf.jsqlparser.expression.Function; |
| 12 | +import net.sf.jsqlparser.expression.IntervalExpression; |
12 | 13 | import net.sf.jsqlparser.expression.LongValue; |
13 | 14 | import net.sf.jsqlparser.expression.StringValue; |
14 | 15 | import net.sf.jsqlparser.expression.TimeValue; |
15 | 16 | import net.sf.jsqlparser.expression.TimestampValue; |
16 | 17 | import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication; |
| 18 | +import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction; |
17 | 19 | import net.sf.jsqlparser.expression.operators.relational.EqualsTo; |
18 | 20 | import net.sf.jsqlparser.expression.operators.relational.GreaterThan; |
19 | 21 | import net.sf.jsqlparser.expression.operators.relational.InExpression; |
|
30 | 32 | import net.sf.jsqlparser.statement.select.Select; |
31 | 33 | import net.sf.jsqlparser.statement.select.SelectExpressionItem; |
32 | 34 | import net.sf.jsqlparser.statement.select.SetOperationList; |
33 | | -import net.sf.jsqlparser.util.deparser.ExpressionDeParser; |
34 | | -import net.sf.jsqlparser.util.deparser.SelectDeParser; |
35 | | -import net.sf.jsqlparser.util.deparser.StatementDeParser; |
36 | 35 | import org.apache.commons.io.IOUtils; |
37 | 36 | import static net.sf.jsqlparser.test.TestUtils.*; |
38 | 37 |
|
@@ -952,4 +951,37 @@ public void testValues6BothVariants() throws JSQLParserException { |
952 | 951 | String stmt = "SELECT I FROM (VALUES 1, 2, 3) AS MY_TEMP_TABLE(I) WHERE I IN (SELECT * FROM (VALUES 1, 2) AS TEST)"; |
953 | 952 | assertSqlCanBeParsedAndDeparsed(stmt); |
954 | 953 | } |
| 954 | + |
| 955 | + public void testInterval1() throws JSQLParserException { |
| 956 | + String stmt = "SELECT 5 + INTERVAL '3 days'"; |
| 957 | + assertSqlCanBeParsedAndDeparsed(stmt); |
| 958 | + } |
| 959 | + |
| 960 | + public void testInterval2() throws JSQLParserException { |
| 961 | + String stmt = "SELECT to_timestamp(to_char(now() - INTERVAL '45 MINUTE', 'YYYY-MM-DD-HH24:')) AS START_TIME FROM tab1"; |
| 962 | + assertSqlCanBeParsedAndDeparsed(stmt); |
| 963 | + |
| 964 | + Statement st = CCJSqlParserUtil.parse(stmt); |
| 965 | + Select select = (Select) st; |
| 966 | + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); |
| 967 | + |
| 968 | + assertEquals(1, plainSelect.getSelectItems().size()); |
| 969 | + SelectExpressionItem item = (SelectExpressionItem) plainSelect.getSelectItems().get(0); |
| 970 | + Function function = (Function)item.getExpression(); |
| 971 | + |
| 972 | + assertEquals("to_timestamp", function.getName()); |
| 973 | + |
| 974 | + assertEquals(1, function.getParameters().getExpressions().size()); |
| 975 | + |
| 976 | + Function func2 = (Function) function.getParameters().getExpressions().get(0); |
| 977 | + |
| 978 | + assertEquals("to_char", func2.getName()); |
| 979 | + |
| 980 | + assertEquals(2, func2.getParameters().getExpressions().size()); |
| 981 | + Subtraction sub = (Subtraction) func2.getParameters().getExpressions().get(0); |
| 982 | + assertTrue(sub.getRightExpression() instanceof IntervalExpression); |
| 983 | + IntervalExpression iexpr = (IntervalExpression) sub.getRightExpression(); |
| 984 | + |
| 985 | + assertEquals("'45 MINUTE'", iexpr.getParameter()); |
| 986 | + } |
955 | 987 | } |
0 commit comments