File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
main/jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/statement/select Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -1609,9 +1609,13 @@ SelectBody SetOperationList() #SetOperationList: {
16091609 } else {
16101610 if (selects.size()>1 && selects.get(selects.size()-1) instanceof PlainSelect) {
16111611 PlainSelect ps = (PlainSelect)selects.get(selects.size()-1);
1612- if (ps.getOrderByElements() != null) {
1612+ if (ps.getOrderByElements() != null && !brackets.get(brackets.size() - 1) ) {
16131613 list.setOrderByElements(ps.getOrderByElements());
1614+ list.setLimit(ps.getLimit());
1615+ list.setOffset(ps.getOffset());
16141616 ps.setOrderByElements(null);
1617+ ps.setLimit(null);
1618+ ps.setOffset(null);
16151619 }
16161620 }
16171621 list.setBracketsOpsAndSelects(brackets,selects,operations);
Original file line number Diff line number Diff line change @@ -882,6 +882,12 @@ public void testSelectItems() throws JSQLParserException {
882882 assertStatementCanBeDeparsedAs (select , statement );
883883 }
884884
885+ @ Test
886+ public void testUnionWithOrderByAndLimitAndNoBrackets () throws JSQLParserException {
887+ String stmt = "SELECT id FROM table1 UNION SELECT id FROM table2 ORDER BY id ASC LIMIT 55" ;
888+ assertSqlCanBeParsedAndDeparsed (stmt );
889+ }
890+
885891 @ Test
886892 public void testUnion () throws JSQLParserException {
887893 String statement = "SELECT * FROM mytable WHERE mytable.col = 9 UNION "
You can’t perform that action at this time.
0 commit comments