Skip to content

Use OFFSET syntax to make pageInfo.hasPrevious page work #170

@legomind

Description

@legomind

I have submitted #169 to start addressing MSSQL server support, but then I discovered that a where clause is being used to window the query instead of offset.

The COUNT(1) OVER() statement will only return the count constrained by the where clause, so pageInfo.hasPrevious will never return true.

If the OFFSET was used instead, the count query would return the entire count, so hasPrevious would work as designed.

The only way that I can see this working is with a query like this:

SELECT [id]
    , COUNT(1) OVER () AS [full_count]

FROM [Users] AS [User]

--Include where clause here if specified by user

ORDER BY [User].[id]

ASC OFFSET (
    SELECT ISNULL(
        (SELECT ROW_NUMBER() OVER(ORDER BY Id) FROM dbo.Users WHERE id = @LastId), --Include where clause here if specified by user
        (SELECT COUNT(*) FROM dbo.Users) --Include where clause here if specified by user
    )
) ROWS
FETCH NEXT 1 ROWS ONLY

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions