@@ -7,6 +7,8 @@ public class PostgresOrderByTerm implements PostgresExpression {
77
88 private final PostgresExpression expr ;
99 private final PostgresOrder order ;
10+ private final int limit ;
11+ private final boolean ties ;
1012
1113 public enum PostgresOrder {
1214 ASC , DESC ;
@@ -22,6 +24,15 @@ public PostgresOrderByTerm(PostgresExpression expr, PostgresOrder order) {
2224 }
2325 this .expr = expr ;
2426 this .order = order ;
27+
28+ if (Randomly .getBooleanWithRatherLowProbability ()) {
29+ this .limit = (int ) Randomly .getPositiveOrZeroNonCachedInteger ();
30+ this .ties = true ;
31+ } else {
32+ this .limit = 0 ;
33+ this .ties = false ;
34+ }
35+
2536 }
2637
2738 // Constructor for window functions, might be removed in the future to have only one constructor
@@ -31,6 +42,8 @@ public PostgresOrderByTerm(PostgresExpression expr, boolean ascending) {
3142 }
3243 this .expr = expr ;
3344 this .order = ascending ? PostgresOrder .ASC : PostgresOrder .DESC ;
45+ this .limit = 0 ;
46+ this .ties = false ;
3447 }
3548
3649 public PostgresExpression getExpr () {
@@ -57,6 +70,10 @@ public PostgresDataType getExpressionType() {
5770
5871 @ Override
5972 public String toString () {
60- return String .format ("%s %s" , expr , order );
73+ if (ties ) {
74+ return String .format ("%s %s FETCH FIRST %d WITH TIES" , expr , order , limit );
75+ } else {
76+ return String .format ("%s %s" , expr , order );
77+ }
6178 }
6279}
0 commit comments