Skip to content

Sorted pagination skips or repeats numeric rows without column affinity #3056

Closed

Description

@peterolkhov

Sorted pagination can skip or repeat rows when a SQLite column has no type affinity:

CREATE TABLE numbers (id INTEGER PRIMARY KEY, value);
INSERT INTO numbers VALUES (1,1),(2,2),(3,3),(4,4),(5,5);

With _size=2&_sort=value, the table API returns 1 and 2, then an empty page when following next_url. With _sort_desc=value, following the links repeats 5 and 4. The probe stops after four pages. CREATE TABLE AS SELECT also creates this kind of column, so this affects ordinary derived tables.

The cursor serializes the numeric sort value as text. On the next request SQLite compares a number to a text binding without affinity conversion. INTEGER/REAL columns and text-only controls paginate correctly. Mixed numeric/text columns also lose rows, so guessing a numeric type or casting every value would be wrong.

This is separate from #3054/#3055: these values are unique, and the loss occurs at the cursor value boundary. Preserving the sort scalar's type in the opaque token should address it without changing primary-key URLs.

Reproduced through Datasette.client and real temporary SQLite databases on main 4e70219b, Python 3.13.14 / SQLite 3.53.1. AI assistance was used for investigation and the bounded reproductions.

Activity

  1. added this to the Datasette 1.0 stable milestone on Nov 15, 2026
  2. added a commit that references this issue on Nov 15, 2026
  3. added a commit that references this issue on Nov 16, 2026
    a355c35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions