{"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/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-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-377072022", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/190", "id": 377072022, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzA3MjAyMg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-28T23:32:24Z", "updated_at": "2018-03-28T23:32:24Z", "author_association": "OWNER", "body": "Here's the SQL for a next page with three compound primary keys:\r\n\r\nhttps://datasette-issue-190-compound-pks.now.sh/compound-pks-8e99805?sql=select+*+from+compound_three_primary_keys%0D%0Awhere%0D%0A++%28pk1+%3E+%3Apk1%29%0D%0A++++or%0D%0A++%28pk1+%3D+%3Apk1+and+pk2+%3E+%3Apk2%29%0D%0A++++or%0D%0A++%28pk1+%3D+%3Apk1+and+pk2+%3D+%3Apk2+and+pk3+%3E+%3Apk3%29%0D%0Aorder+by+pk1%2C+pk2%2C+pk3%3B%0D%0A%0D%0A%0D%0A&pk1=a&pk2=d&pk3=v\r\n\r\n```\r\nselect * from compound_three_primary_keys\r\nwhere\r\n (pk1 > :pk1)\r\n or\r\n (pk1 = :pk1 and pk2 > :pk2)\r\n or\r\n (pk1 = :pk1 and pk2 = :pk2 and pk3 > :pk3)\r\norder by pk1, pk2, pk3;\r\n```", "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-377067541", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/190", "id": 377067541, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzA2NzU0MQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-28T23:09:18Z", "updated_at": "2018-03-28T23:09:51Z", "author_association": "OWNER", "body": "Here's how I generated the table for testing this with 3 compound primary keys:\r\n\r\n CREATE_SQL = '''\r\n CREATE TABLE compound_three_primary_keys (\r\n pk1 varchar(30),\r\n pk2 varchar(30),\r\n pk3 varchar(30),\r\n content text,\r\n PRIMARY KEY (pk1, pk2, pk3)\r\n );'''\r\n alphabet = 'abcdefghijklmnopqrstuvwxyz'\r\n for a in alphabet:\r\n for b in alphabet:\r\n for c in alphabet:\r\n print('''\r\n INSERT INTO compound_three_primary_keys VALUES ('{}', '{}', '{}', '{}');\r\n '''.strip().format(a, b, c, '{}-{}-{}-{}-{}-{}'.format(a,b,c,a,b,c)))\r\n", "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-377066466", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/190", "id": 377066466, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzA2NjQ2Ng==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-28T23:03:45Z", "updated_at": "2018-03-28T23:03:57Z", "author_association": "OWNER", "body": "Without row values syntax, the necessary SQL to retrieve the next page after `d, v` gets a bit gnarly:\r\n\r\n select * from compound_primary_key\r\n where pk1 >= \"d\" and not (pk1 = \"d\" and pk2 <= \"v\")\r\n order by pk1, pk2\r\n\r\nSee https://datasette-issue-190-compound-pks.now.sh/compound-pks-9aafe8f?sql=select+*+from+compound_primary_key+where+pk1+%3E%3D+%22d%22+and+not+%28pk1+%3D+%22d%22+and+pk2+%3C%3D+%22v%22%29+order+by+pk1%2C+pk2\r\n\r\nThis article was useful for figuring this out: https://use-the-index-luke.com/sql/partial-results/fetch-next-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/190#issuecomment-377065541", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/190", "id": 377065541, "node_id": "MDEyOklzc3VlQ29tbWVudDM3NzA2NTU0MQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2018-03-28T22:58:52Z", "updated_at": "2018-03-28T22:58:52Z", "author_association": "OWNER", "body": "This is because the SQL we are using here is:\r\n\r\n select * from compound_primary_key where \"pk1\" > \"d\" and \"pk2\" > \"v\" order by pk1, pk2 limit 101\r\n\r\nThis is incorrect. The correct SQL syntax (according to the example on https://www.sqlite.org/rowvalue.html#scrolling_window_queries ) is:\r\n\r\n select * from compound_primary_key where (\"pk1\", \"pk2\") > (\"d\", \"v\") order by pk1, pk2 limit 101\r\n\r\nBUT... this uses \"row values\" syntax which was only added to SQLite in version 3.15.0 in October 2016: https://sqlite.org/changes.html#version_3_15_0\r\n\r\nThe version on https://datasette-issue-190-compound-pks.now.sh/compound-pks-9aafe8f?sql=select+sqlite_version%28%29%3B is 3.8.7.1 from October 2014.", "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}