Skip to content

Commit 46f5197

Browse files
committed
fixes #122
1 parent 68f47dc commit 46f5197

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,21 @@ String RelObjectName():
527527
{ return tk.image; }
528528
}
529529

530+
/*
531+
Extended usage of object names.
532+
*/
533+
String RelObjectNameExt():
534+
{ Token tk = null;
535+
String result=null;
536+
}
537+
{
538+
( result=RelObjectName() | tk=<K_LEFT> | tk=<K_RIGHT> )
539+
{
540+
if (tk!=null) result=tk.image;
541+
return result;
542+
}
543+
}
544+
530545
Table Table():
531546
{
532547
String serverName = null, databaseName = null, schemaName = null, tableName = null;
@@ -2067,9 +2082,9 @@ Function Function():
20672082
{
20682083
["{fn" { retval.setEscaped(true); } ]
20692084

2070-
funcName=RelObjectName()
2085+
funcName=RelObjectNameExt()
20712086

2072-
[ "." tmp=RelObjectName() { funcName+= "." + tmp; } ["." tmp=RelObjectName() { funcName+= "." + tmp; }]]
2087+
[ "." tmp=RelObjectNameExt() { funcName+= "." + tmp; } ["." tmp=RelObjectNameExt() { funcName+= "." + tmp; }]]
20732088
"(" [ [<K_DISTINCT> { retval.setDistinct(true); } | <K_ALL> { retval.setAllColumns(true); }] (expressionList=SimpleExpressionList() | "*" { retval.setAllColumns(true); }) ] ")"
20742089

20752090
[ "." tmp=RelObjectName() { retval.setAttribute(tmp); }]

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,16 @@ public void testAnalyticFunctionProblem1b() throws JSQLParserException {
12121212
String statement = "SELECT last_value(s.revenue_hold) OVER (PARTITION BY s.id_d_insertion_order, s.id_d_product_ad_attr, trunc(s.date_id, 'mm') ORDER BY s.date_id ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS col FROM s";
12131213
assertSqlCanBeParsedAndDeparsed(statement);
12141214
}
1215+
1216+
public void testFunctionLeft() throws JSQLParserException {
1217+
String statement = "SELECT left(table1.col1, 4) FROM table1";
1218+
assertSqlCanBeParsedAndDeparsed(statement);
1219+
}
1220+
1221+
public void testFunctionRight() throws JSQLParserException {
1222+
String statement = "SELECT right(table1.col1, 4) FROM table1";
1223+
assertSqlCanBeParsedAndDeparsed(statement);
1224+
}
12151225

12161226
public void testOracleJoin() throws JSQLParserException {
12171227
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a = tabelle2.b(+)";

0 commit comments

Comments
 (0)