@@ -457,7 +457,7 @@ func (sb *SelectBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
457
457
buf .WriteLeadingString ("LIMIT " )
458
458
buf .WriteString (sb .limitVar )
459
459
}
460
- case PostgreSQL , Presto :
460
+ case PostgreSQL :
461
461
if len (sb .limitVar ) > 0 {
462
462
buf .WriteLeadingString ("LIMIT " )
463
463
buf .WriteString (sb .limitVar )
@@ -467,6 +467,20 @@ func (sb *SelectBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
467
467
buf .WriteLeadingString ("OFFSET " )
468
468
buf .WriteString (sb .offsetVar )
469
469
}
470
+ case Presto :
471
+ // There might be a hidden constraint in Presto requiring offset to be set before limit.
472
+ // The select statement documentation (https://prestodb.io/docs/current/sql/select.html)
473
+ // puts offset before limit, and Trino, which is based on Presto, seems
474
+ // to require this specific order.
475
+ if len (sb .offsetVar ) > 0 {
476
+ buf .WriteLeadingString ("OFFSET " )
477
+ buf .WriteString (sb .offsetVar )
478
+ }
479
+
480
+ if len (sb .limitVar ) > 0 {
481
+ buf .WriteLeadingString ("LIMIT " )
482
+ buf .WriteString (sb .limitVar )
483
+ }
470
484
471
485
case SQLServer :
472
486
// If ORDER BY is not set, sort column #1 by default.
0 commit comments