@@ -411,20 +411,19 @@ def limit_clause(self, select, **kw):
411411 # handle the limit and offset clauses
412412 if not self .dialect .supports_modern_pagination :
413413 return ""
414+ sql = ""
414415 if select ._has_row_limiting_clause and not self ._use_top (select ):
415416 limit_clause = self ._get_limit_or_fetch (select )
416417 offset_clause = select ._offset_clause
417418
418419 if limit_clause is not None :
419- if offset_clause is not None :
420- return " LIMIT %s OFFSET %s" % (
421- self .process (limit_clause , ** kw ),
422- self .process (offset_clause , ** kw ),
423- )
424- else :
425- return " LIMIT %s" % self .process (limit_clause , ** kw )
426- else :
427- return ""
420+ sql += " LIMIT %s" % self .process (limit_clause , ** kw )
421+ elif offset_clause is not None and self .dialect .server_version_info < (2025 , 2 ):
422+ # IRIS 2025.1 has a bug with offset without limit
423+ sql += " LIMIT 100"
424+ if offset_clause is not None :
425+ sql += " OFFSET %s" % self .process (offset_clause , ** kw )
426+ return sql
428427
429428 def fetch_clause (self , select , ** kw ):
430429 if not self .dialect .supports_modern_pagination :
@@ -506,6 +505,8 @@ def get_select_precolumns(self, select, **kw):
506505 return text
507506
508507 def _use_top (self , select ):
508+ if self .dialect .supports_modern_pagination :
509+ return False
509510 return (select ._offset_clause is None ) and (
510511 select ._simple_int_clause (select ._limit_clause )
511512 or select ._simple_int_clause (select ._fetch_clause )
@@ -631,11 +632,11 @@ def _handle_modern_pagination(self, select, select_stmt):
631632
632633 def order_by_clause (self , select , ** kw ):
633634 order_by = self .process (select ._order_by_clause , ** kw )
635+ limit_clause = self ._get_limit_or_fetch (select )
634636
635- if order_by and ( not self .is_subquery () or select ._limit ) :
637+ if order_by and not self .is_subquery () and limit_clause is None and select ._offset_clause is None :
636638 return " ORDER BY " + order_by
637- else :
638- return ""
639+ return ""
639640
640641 def visit_concat_op_binary (self , binary , operator , ** kw ):
641642 return "STRING(%s, %s)" % (
0 commit comments