Skip to content

Commit c2ad9d2

Browse files
author
LionelNirva
committed
Unit test for the fix Bug when Deparsing SQL Server request having TOP
and DISTINCT clauses.
1 parent 7ac7002 commit c2ad9d2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,19 @@ public void testDistinct() throws JSQLParserException {
408408
assertStatementCanBeDeparsedAs(select, statement);
409409
}
410410

411+
public void testDistinctTop() throws JSQLParserException {
412+
String statement = "SELECT DISTINCT TOP 5 myid, mycol FROM mytable WHERE mytable.col = 9";
413+
Select select = (Select) parserManager.parse(new StringReader(statement));
414+
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
415+
assertEquals("myid",
416+
((Column) ((SelectExpressionItem) plainSelect.getSelectItems().get(0)).getExpression())
417+
.getColumnName());
418+
assertEquals("mycol",
419+
((Column) ((SelectExpressionItem) plainSelect.getSelectItems().get(1)).getExpression()).getColumnName());
420+
assertNotNull(plainSelect.getTop());
421+
assertStatementCanBeDeparsedAs(select, statement);
422+
}
423+
411424
public void testFrom() throws JSQLParserException {
412425
String statement = "SELECT * FROM mytable as mytable0, mytable1 alias_tab1, mytable2 as alias_tab2, (SELECT * FROM mytable3) AS mytable4 WHERE mytable.col = 9";
413426
String statementToString = "SELECT * FROM mytable AS mytable0, mytable1 alias_tab1, mytable2 AS alias_tab2, (SELECT * FROM mytable3) AS mytable4 WHERE mytable.col = 9";

0 commit comments

Comments
 (0)