Skip to content

Commit ae7810b

Browse files
committed
fix: calculate limit value correctly for offset only queries
1 parent e879aad commit ae7810b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def limit_clause(self, select, **kw):
260260
if select._offset_clause is not None:
261261
if select._limit_clause is None:
262262
text += "\n LIMIT 9223372036854775805"
263+
# text += f"\n LIMIT {9223372036854775807-select._offset}"
263264
text += " OFFSET " + self.process(select._offset_clause, **kw)
264265
return text
265266

test/test_suite.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,31 @@ def test_staleness(self):
16161616
assert connection.connection.staleness is None
16171617

16181618

1619+
class LimitOffsetTest(fixtures.TestBase):
1620+
"""
1621+
Check that the limit and offset statements are being generated correctly.
1622+
"""
1623+
1624+
def setUp(self):
1625+
self._engine = create_engine(get_db_url(), pool_size=1)
1626+
self._metadata = MetaData(bind=self._engine)
1627+
1628+
self._table = Table(
1629+
"execution_options",
1630+
self._metadata,
1631+
Column("opt_id", Integer, primary_key=True),
1632+
Column("opt_name", String(16), nullable=False),
1633+
)
1634+
1635+
self._metadata.create_all(self._engine)
1636+
1637+
def test_offset_only(self):
1638+
for offset in [1, 7, 10, 100, 1000, 10000]:
1639+
1640+
with self._engine.connect().execution_options(read_only=True) as connection:
1641+
list(connection.execute(self._table.select().offset(offset)).fetchall())
1642+
1643+
16191644
class ComputedReflectionFixtureTest(_ComputedReflectionFixtureTest):
16201645
@classmethod
16211646
def define_tables(cls, metadata):

0 commit comments

Comments
 (0)