livehelpnow / tds_ecto

TDS Adapter for Ecto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect syntax near 'OFFSET' when using Limit

aristotelesbr opened this issue · comments

Does not seem to support SQL Server 2008 R2 when using 'OFFSET'.

** (Tds.Error) Line 1 (Error 102): Incorrect syntax near 'OFFSET'.
    (ecto) lib/ecto/adapters/sql.ex:431: Ecto.Adapters.SQL.execute_and_cache/7
    (ecto) lib/ecto/repo/queryable.ex:133: Ecto.Repo.Queryable.execute/5
    (ecto) lib/ecto/repo/queryable.ex:37: Ecto.Repo.Queryable.all/4
    (phoenix_pagination) lib/phoenix_pagination.ex:46: Phoenix.Pagination.paginate/3

it is not supported because there are many ways to build such query and none of them is silver bullet. So I'm afraid, and advise you to code it by hand and see what solution is best for your case.

For instance

SELECT ees.*
FROM Employees ees
JOIN 
(SELECT EmployeeID, rownum= ROW_NUMBER()
FROM Employees
ORDER BY EmployeeLastName, EmployeeFirstname) 
eelist ON eelist.EmployeeID = ees.EmployeeID
WHERE eelist.rownum BETWEEN 1000 AND 1050

this solution is fast when you want to get first page, but with large tables, with each new page it takes longer to get that page than in previous page fetch.

Second, if you join or left join table in query, what should be counted as page row number?!? Each row, or you need "over partition" and what is partition, and what is total number of rows?

@mjaric,

I'm trying to implement simple paging using any of these libs:
Rummage
scrivener
kerosene
But the mistake I get is always the same.
I had a similar problem (using rails) with a gem that also used the Tds project using an older version of the framework I normally use OFFSET activerecord-sqlserver-adapter
Sorry, my English is not good.

I will try to do as you recommended.