improved pg parser, fix #4266

This commit is contained in:
高铁
2021-05-04 13:56:56 +08:00
parent ea174f36e1
commit dfdb95691e
3 changed files with 20 additions and 4 deletions
@@ -109,11 +109,18 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
} else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) {
print0(ucase ? "DISTINCT " : "distinct ");
if (x.getDistinctOn() != null && x.getDistinctOn().size() > 0) {
List<SQLExpr> distinctOn = x.getDistinctOn();
if (distinctOn != null && distinctOn.size() > 0) {
print0(ucase ? "ON " : "on ");
print0("(");
printAndAccept(x.getDistinctOn(), ", ");
print0(") ");
if (distinctOn.size() == 1 && distinctOn.get(0) instanceof SQLListExpr) {
printExpr(distinctOn.get(0));
print(' ');
} else {
print0("(");
printAndAccept(distinctOn, ", ");
print0(") ");
}
}
}
@@ -88,6 +88,10 @@ public class PostgresqlResourceTest extends PGTest {
exec_test("bvt/parser/postgresql-12.txt");
}
public void test_13() throws Exception {
exec_test("bvt/parser/postgresql-13.txt");
}
public void exec_test(String resource) throws Exception {
System.out.println(resource);
InputStream is = null;
@@ -0,0 +1,5 @@
select distinct on (a,b) a,b from table order by a,b
---------------------------
SELECT DISTINCT ON (a, b) a, b
FROM table
ORDER BY a, b