cloudflare / sqlalchemy-clickhouse

Apache License 2.0
314 stars 105 forks source link

limit and offset are not working as expected. #56

Closed aravindkarnam closed 2 months ago

aravindkarnam commented 4 years ago

Here's the code snippet.

table = Company.__table__.c
columns = [
        table.name,
        table.employees,
        table.registered,
        table.city,
        table.country,
        table.industry,
        table.revenue]
query = select(columns)
if order_by:
        query = query.order_by(order_by)
if limit:
        query = query.limit(limit)
if offset:
        query = query.offset(offset)

engine = create_engine(
        "clickhouse://{}:{}@{}:{}/{}".format(
            CH_DB_USER,
            CH_DB_PASS,
            CH_DB_HOST,
            CH_DB_PORT,
            CH_DB_NAME))
clickhouse_db_conn = engine.connect()
results = db_connections.clickhouse_db_conn.execute(query)

The problem I'm facing is with limit and offset. Instead of returning "limit" number of results from starting from "offset", I'm getting "offset" number of results when i execute the query.

For example: limit =10 and offset =20 is returning 20 results, instead of 10 results with offset at 20

If I removed the whole offset part then limit clause by itself is working correctly. Only when I apply offset, the library is interpreting value provided to offset clause as value for limit and returning results accordingly. I've double checked to make sure that I'm passing in correct values. This is final block in rolling out a new feature, any temporary work around from community is greatly appreciated. Thanks.

aravindkarnam commented 4 years ago

Added a patch for this here. https://github.com/cloudflare/sqlalchemy-clickhouse/pull/57/commits/56c603e9397aee7cedc5daa5603ef5bfe05aa551

aravindkarnam commented 4 years ago

@vavrusa Could you please check and merge this.

vavrusa commented 4 years ago

https://github.com/cloudflare/sqlalchemy-clickhouse/pull/57