{"html_url": "https://github.com/simonw/datasette/issues/190#issuecomment-377454591", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/190", "id": 377454591, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzQ1NDU5MQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-30T06:11:59Z", "updated_at": "2018-03-30T06:11:59Z", "author_association": "OWNER", "body": "Re-opening this issue: my fix doesn't play nicely with extra filter arguments.\r\n\r\nConsider this page: https://datasette-issue-190-compound-pks-not-quite-fixed.now.sh/compound-pks-8e99805/compound_three_primary_keys?content__contains=d\r\n\r\nThe next link is to `?_next=f%2Cz%2Ct&content__contains=z` (that's next of `f,z,t`) but that gives us https://datasette-issue-190-compound-pks-not-quite-fixed.now.sh/compound-pks-8e99805/compound_three_primary_keys?_next=b%2Cx%2Cd&content__contains=d which shows `a,a,d` at the top.\r\n\r\nSure enough, the generated SQL looks like this: https://datasette-issue-190-compound-pks-not-quite-fixed.now.sh/compound-pks-8e99805?sql=select+%2A+from+compound_three_primary_keys+where+%22content%22+like+%3Ap0+and+%28%5Bpk1%5D+%3E+%3Ap0%29%0A++or%0A%28%5Bpk1%5D+%3D+%3Ap0+and+%5Bpk2%5D+%3E+%3Ap1%29%0A++or%0A%28%5Bpk1%5D+%3D+%3Ap0+and+%5Bpk2%5D+%3D+%3Ap1+and+%5Bpk3%5D+%3E+%3Ap2%29+order+by+pk1%2C+pk2%2C+pk3+limit+101&p0=%25d%25&p1=b&p2=x&p3=d\r\n\r\n\tselect * from compound_three_primary_keys where \"content\" like :p0 and ([pk1] > :p0)\r\n\t or\r\n\t([pk1] = :p0 and [pk2] > :p1)\r\n\t or\r\n\t([pk1] = :p0 and [pk2] = :p1 and [pk3] > :p2) order by pk1, pk2, pk3 limit 101\r\n\r\nThe parameters here are confused. The :p0 should be reserved just for the like clause - the other parameters should be p1, p2 and p3 (not p0, p1 and p2).", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 309558826, "label": "Keyset pagination doesn't work correctly for compound primary keys"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/190#issuecomment-377457087", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/190", "id": 377457087, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzQ1NzA4Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-30T06:30:23Z", "updated_at": "2018-03-30T06:30:23Z", "author_association": "OWNER", "body": "Interestingly, in deploying a copy of the database to demonstrate this final bug fix I had to use the `--force` argument like so:\r\n\r\n datasette publish now --branch=master compound-pks.db --force\r\n\r\nThis is because `now` had already deployed a Dockerfile referencing `--branch=master` once already, so it thought nothing had changed and it could re-use that last deployment.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 309558826, "label": "Keyset pagination doesn't work correctly for compound primary keys"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/190#issuecomment-377457214", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/190", "id": 377457214, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzQ1NzIxNA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-30T06:31:15Z", "updated_at": "2018-03-30T06:31:15Z", "author_association": "OWNER", "body": "Fixed! https://datasette-issue-190-compound-pks-second-fix.now.sh/compound-pks-8e99805/compound_three_primary_keys?_next=b%2Cx%2Cd&content__contains=d now correctly shows `b,y,d` as the first row on the page.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 309558826, "label": "Keyset pagination doesn't work correctly for compound primary keys"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/189#issuecomment-377459579", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/189", "id": 377459579, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzQ1OTU3OQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-30T06:47:52Z", "updated_at": "2018-03-30T06:47:52Z", "author_association": "OWNER", "body": "I'm not entirely sure how to get `_next=` pagination working against sorted collections when a tie-breaker is needed.\r\n\r\nConsider this data:\r\n\r\nhttps://fivethirtyeight.datasettes.com/fivethirtyeight-2628db9?sql=select+rowid%2C+*+from+%5Bnfl-wide-receivers%2Fadvanced-historical%5D%0D%0Aorder+by+case+when+career_ranypa+is+null+then+1+else+0+end%2C+career_ranypa%2C+rowid+limit+11\r\n\r\n![2018-03-29 at 11 46 pm](https://user-images.githubusercontent.com/9599/38127549-790c8bd0-33ab-11e8-8d32-66f5d3847c8a.png)\r\n\r\nIf the page size was set to 9 rather than 11, the page divide would be between those two rows with the same value in the `career_ranypa` column. What would the `?_next=` token look like such that the correct row would be returned?\r\n\r\n", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 309471814, "label": "Ability to sort (and paginate) by column"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/189#issuecomment-377460127", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/189", "id": 377460127, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzQ2MDEyNw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-30T06:51:29Z", "updated_at": "2018-03-30T06:51:52Z", "author_association": "OWNER", "body": "The problem is that our `_next=` pagination currently works based on a `>` - but for this case a `>=` for the value is needed combined with a `>` on the tie-breaker (which would be the `rowid` column).\r\n\r\nSo I think this is the right SQL:\r\n\r\n```\r\nselect rowid, * from [nfl-wide-receivers/advanced-historical]\r\nwhere career_ranypa >= -6.331167749 and rowid > 2736\r\norder by case when career_ranypa is null then 1 else 0 end, career_ranypa, rowid limit 11\r\n```\r\n\r\nhttps://fivethirtyeight.datasettes.com/fivethirtyeight-2628db9?sql=select+rowid%2C+*+from+%5Bnfl-wide-receivers%2Fadvanced-historical%5D%0D%0Awhere+career_ranypa+%3E%3D+-6.331167749+and+rowid+%3E+2736%0D%0Aorder+by+case+when+career_ranypa+is+null+then+1+else+0+end%2C+career_ranypa%2C+rowid+limit+11\r\n\r\nBut how do I encode a `_next` token that means \">= X and > Y\"?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 309471814, "label": "Ability to sort (and paginate) by column"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/189#issuecomment-377462334", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/189", "id": 377462334, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzQ2MjMzNA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-30T07:06:21Z", "updated_at": "2018-03-30T07:06:21Z", "author_association": "OWNER", "body": "Maybe the answer here is that anything that's encoded in the next token is treated as >= with the exception of columns known to be primary keys, which are treated as >", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 309471814, "label": "Ability to sort (and paginate) by column"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/189#issuecomment-377546510", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/189", "id": 377546510, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzU0NjUxMA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-30T15:13:11Z", "updated_at": "2018-03-30T15:13:11Z", "author_association": "OWNER", "body": "Pushed some work-in-progress with failing unit tests here: https://github.com/simonw/datasette/commit/2f8359c6f25768805431c80c74e5ec4213c2b2a6\r\n\r\nHere's a demo: https://datasette-column-sort-wip.now.sh/sortable-4bbaa6f/sortable?_sort=sortable - note that the `_sort_desc` and `_sort_nulls_last` options aren't done yet, plus it doesn't correctly paginate (the `_next` tokens do not yet take sorting into account).", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 309471814, "label": "Ability to sort (and paginate) by column"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/189#issuecomment-377547265", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/189", "id": 377547265, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzU0NzI2NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-30T15:16:43Z", "updated_at": "2018-03-30T15:16:43Z", "author_association": "OWNER", "body": "I think this is the right incantation for a \"next\" link: https://datasette-column-sort-wip.now.sh/sortable-4bbaa6f?sql=select+*+from+sortable%0D%0Awhere+sortable+%3C%3D+94%0D%0Aand+%28%0D%0A++%28pk1+%3E+%27d%27%29%0D%0A++or%0D%0A++%28pk1+%3D+%27d%27+and+pk2+%3E+%27w%27%29%0D%0A%29%0D%0Aorder+by+sortable+desc%2C+pk1%2C+pk2%0D%0Alimit+7", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 309471814, "label": "Ability to sort (and paginate) by column"}, "performed_via_github_app": null}