Skip to content

Commit

Permalink
fix: FromItem with Alias without AS keyword
Browse files Browse the repository at this point in the history
- `VALUES ... T(x,y)`

Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
  • Loading branch information
manticore-projects committed May 30, 2024
1 parent 7479342 commit 5f580af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,7 @@ Alias Alias():
{
(
LOOKAHEAD(3) (
// Aliases with Columns:
// Aliases with AS and Columns, but optional identifier:
// SELECT fun(x) AS (a,b,c)
// SELECT fun(x) AS T(a,b,c)
<K_AS>
Expand All @@ -2667,23 +2667,20 @@ Alias Alias():
)
|
(
// Aliases without Columns:
// Aliases with identifier but optional AS and Columns:
// SELECT fun(x) AS T
// SELECT fun(x) T
// SELECT fun(x) T(a,b,c)

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

/* Should not be allowed/needed
We can bring this back only if people complain

[ LOOKAHEAD(2) "(" { List<Alias.AliasColumn> list = new ArrayList<Alias.AliasColumn>(); }
colname = RelObjectName() [ colDataType = ColDataType() ] { list.add(new Alias.AliasColumn(colname, colDataType)); }
("," { colDataType=null; } colname = RelObjectName() [ colDataType = ColDataType()] { list.add(new Alias.AliasColumn(colname, colDataType)); } )*
")" { alias.setAliasColumns(list); } ]

*/
)
)
{ return alias; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@ public void testObject() {

valuesStatement.accept(new StatementVisitorAdapter());
}

@Test
public void testValuesWithAliasWithoutAs() throws JSQLParserException {
String sqlStr = "SELECT a, b, cume_dist() OVER (PARTITION BY a ORDER BY b) AS cume_dist\n" +
" FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);";
assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
}

0 comments on commit 5f580af

Please sign in to comment.