Skip to content

Commit 5f580af

Browse files
fix: FromItem with Alias without AS keyword
- `VALUES ... T(x,y)` Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
1 parent 7479342 commit 5f580af

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,7 @@ Alias Alias():
26502650
{
26512651
(
26522652
LOOKAHEAD(3) (
2653-
// Aliases with Columns:
2653+
// Aliases with AS and Columns, but optional identifier:
26542654
// SELECT fun(x) AS (a,b,c)
26552655
// SELECT fun(x) AS T(a,b,c)
26562656
<K_AS>
@@ -2667,23 +2667,20 @@ Alias Alias():
26672667
)
26682668
|
26692669
(
2670-
// Aliases without Columns:
2670+
// Aliases with identifier but optional AS and Columns:
26712671
// SELECT fun(x) AS T
26722672
// SELECT fun(x) T
2673+
// SELECT fun(x) T(a,b,c)
26732674

26742675
[<K_AS> { useAs = true; } ]
26752676
( name=RelObjectNameWithoutStart() | token=<S_CHAR_LITERAL> { name=token.image; } )
26762677
{ alias = new Alias(name,useAs); }
26772678

2678-
/* Should not be allowed/needed
2679-
We can bring this back only if people complain
2680-
26812679
[ LOOKAHEAD(2) "(" { List<Alias.AliasColumn> list = new ArrayList<Alias.AliasColumn>(); }
26822680
colname = RelObjectName() [ colDataType = ColDataType() ] { list.add(new Alias.AliasColumn(colname, colDataType)); }
26832681
("," { colDataType=null; } colname = RelObjectName() [ colDataType = ColDataType()] { list.add(new Alias.AliasColumn(colname, colDataType)); } )*
26842682
")" { alias.setAliasColumns(list); } ]
26852683

2686-
*/
26872684
)
26882685
)
26892686
{ return alias; }

src/test/java/net/sf/jsqlparser/statement/values/ValuesTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@ public void testObject() {
6464

6565
valuesStatement.accept(new StatementVisitorAdapter());
6666
}
67+
68+
@Test
69+
public void testValuesWithAliasWithoutAs() throws JSQLParserException {
70+
String sqlStr = "SELECT a, b, cume_dist() OVER (PARTITION BY a ORDER BY b) AS cume_dist\n" +
71+
" FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);";
72+
assertSqlCanBeParsedAndDeparsed(sqlStr, true);
73+
}
6774
}

0 commit comments

Comments
 (0)