diff --git a/sharding-sql-test/src/main/resources/sql/supported/dql/select-pagination.xml b/sharding-sql-test/src/main/resources/sql/supported/dql/select-pagination.xml
index cdbae507799d58098be19b5b191b74cf92b1b0c6..d790b3cc9387c54ab032e6dc54edb27a30dcf173 100644
--- a/sharding-sql-test/src/main/resources/sql/supported/dql/select-pagination.xml
+++ b/sharding-sql-test/src/main/resources/sql/supported/dql/select-pagination.xml
@@ -24,6 +24,7 @@
+
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
index 844cdbd5fb92fadc1f1308f0b973ec1c069fa1cd..2dcf5cd3384fa542714cca46246d5334d161bc43 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
@@ -150,11 +150,11 @@ havingClause
;
limitClause
- : limitRowCountSyntax_ limitOffsetSyntax_?
- | limitOffsetSyntax_ limitRowCountSyntax_?
+ : limitRowCountSyntax limitOffsetSyntax?
+ | limitOffsetSyntax limitRowCountSyntax?
;
-limitRowCountSyntax_
+limitRowCountSyntax
: LIMIT (ALL | limitRowCount)
;
@@ -162,7 +162,7 @@ limitRowCount
: numberLiterals | parameterMarker
;
-limitOffsetSyntax_
+limitOffsetSyntax
: OFFSET limitOffset (ROW | ROWS)?
;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/impl/PostgreSQLDMLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/impl/PostgreSQLDMLVisitor.java
index 2ad3a8db60a604a6e1c1771002ea755a4c6af9ff..830075fa8db3ff073665516c19f447a5993a7205 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/impl/PostgreSQLDMLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/impl/PostgreSQLDMLVisitor.java
@@ -406,31 +406,32 @@ public final class PostgreSQLDMLVisitor extends PostgreSQLVisitor {
@Override
public ASTNode visitLimitClause(final LimitClauseContext ctx) {
- if (null != ctx.limitRowCountSyntax_() && null != ctx.limitOffsetSyntax_()) {
+ if (null != ctx.limitRowCountSyntax() && null != ctx.limitOffsetSyntax()) {
return isRowCountBeforeOffset(ctx) ? createLimitSegmentWhenRowCountBeforeOffset(ctx) : createLimitSegmentWhenRowCountAfterOffset(ctx);
}
return createLimitSegmentWhenRowCountOrOffsetAbsent(ctx);
}
private boolean isRowCountBeforeOffset(final LimitClauseContext ctx) {
- return ctx.limitRowCountSyntax_().getStart().getStartIndex() < ctx.limitOffsetSyntax_().getStart().getStartIndex();
+ return ctx.limitRowCountSyntax().getStart().getStartIndex() < ctx.limitOffsetSyntax().getStart().getStartIndex();
}
private LimitSegment createLimitSegmentWhenRowCountBeforeOffset(final LimitClauseContext ctx) {
- LimitValueSegment rowCount = (LimitValueSegment) visit(ctx.limitRowCountSyntax_().limitRowCount());
- LimitValueSegment offset = (LimitValueSegment) visit(ctx.limitOffsetSyntax_().limitOffset());
+ LimitValueSegment rowCount = null == ctx.limitRowCountSyntax().limitRowCount() ? null : (LimitValueSegment) visit(ctx.limitRowCountSyntax().limitRowCount());
+ LimitValueSegment offset = (LimitValueSegment) visit(ctx.limitOffsetSyntax().limitOffset());
return new LimitSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), offset, rowCount);
}
private LimitSegment createLimitSegmentWhenRowCountAfterOffset(final LimitClauseContext ctx) {
- LimitValueSegment offset = (LimitValueSegment) visit(ctx.limitOffsetSyntax_().limitOffset());
- LimitValueSegment rowCount = (LimitValueSegment) visit(ctx.limitRowCountSyntax_().limitRowCount());
+ LimitValueSegment offset = (LimitValueSegment) visit(ctx.limitOffsetSyntax().limitOffset());
+ LimitValueSegment rowCount = null == ctx.limitRowCountSyntax().limitRowCount() ? null : (LimitValueSegment) visit(ctx.limitRowCountSyntax().limitRowCount());
return new LimitSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), offset, rowCount);
}
private LimitSegment createLimitSegmentWhenRowCountOrOffsetAbsent(final LimitClauseContext ctx) {
- LimitValueSegment rowCount = null == ctx.limitRowCountSyntax_() ? null : (LimitValueSegment) visit(ctx.limitRowCountSyntax_().limitRowCount());
- LimitValueSegment offset = null == ctx.limitOffsetSyntax_() ? null : (LimitValueSegment) visit(ctx.limitOffsetSyntax_().limitOffset());
+ LimitValueSegment rowCount = null == ctx.limitRowCountSyntax() || null == ctx.limitRowCountSyntax().limitRowCount()
+ ? null : (LimitValueSegment) visit(ctx.limitRowCountSyntax().limitRowCount());
+ LimitValueSegment offset = null == ctx.limitOffsetSyntax() ? null : (LimitValueSegment) visit(ctx.limitOffsetSyntax().limitOffset());
return new LimitSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), offset, rowCount);
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select-pagination.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select-pagination.xml
index 982365ee3b092568462aa8a43f51985145c5283d..28c65a64f4e6f88ec05a3a13284bf393a2f958f8 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select-pagination.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select-pagination.xml
@@ -296,6 +296,50 @@
+
+
+
+