home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

13 rows where "updated_at" is on date 2018-03-28 sorted by updated_at descending

✖
✖

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: issue_url, updated_at (date)

issue 2

  • Ability to sort (and paginate) by column 9
  • Keyset pagination doesn't work correctly for compound primary keys 4

user 1

  • simonw 13

author_association 1

  • OWNER 13
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions issue performed_via_github_app
377072022 https://github.com/simonw/datasette/issues/190#issuecomment-377072022 https://api.github.com/repos/simonw/datasette/issues/190 MDEyOklzc3VlQ29tbWVudDM3NzA3MjAyMg== simonw 9599 2018-03-28T23:32:24Z 2018-03-28T23:32:24Z OWNER

Here's the SQL for a next page with three compound primary keys:

https://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

select * from compound_three_primary_keys where (pk1 > :pk1) or (pk1 = :pk1 and pk2 > :pk2) or (pk1 = :pk1 and pk2 = :pk2 and pk3 > :pk3) order by pk1, pk2, pk3;

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Keyset pagination doesn't work correctly for compound primary keys 309558826  
377067541 https://github.com/simonw/datasette/issues/190#issuecomment-377067541 https://api.github.com/repos/simonw/datasette/issues/190 MDEyOklzc3VlQ29tbWVudDM3NzA2NzU0MQ== simonw 9599 2018-03-28T23:09:18Z 2018-03-28T23:09:51Z OWNER

Here's how I generated the table for testing this with 3 compound primary keys:

CREATE_SQL = '''
CREATE TABLE compound_three_primary_keys (
    pk1 varchar(30),
    pk2 varchar(30),
    pk3 varchar(30),
    content text,
    PRIMARY KEY (pk1, pk2, pk3)
);'''
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for a in alphabet:
    for b in alphabet:
        for c in alphabet:
            print('''
INSERT INTO compound_three_primary_keys VALUES ('{}', '{}', '{}', '{}');
        '''.strip().format(a, b, c, '{}-{}-{}-{}-{}-{}'.format(a,b,c,a,b,c)))
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Keyset pagination doesn't work correctly for compound primary keys 309558826  
377066466 https://github.com/simonw/datasette/issues/190#issuecomment-377066466 https://api.github.com/repos/simonw/datasette/issues/190 MDEyOklzc3VlQ29tbWVudDM3NzA2NjQ2Ng== simonw 9599 2018-03-28T23:03:45Z 2018-03-28T23:03:57Z OWNER

Without row values syntax, the necessary SQL to retrieve the next page after d, v gets a bit gnarly:

select * from compound_primary_key
where pk1 >= "d" and not (pk1 = "d" and pk2 <= "v")
order by pk1, pk2

See 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

This article was useful for figuring this out: https://use-the-index-luke.com/sql/partial-results/fetch-next-page

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Keyset pagination doesn't work correctly for compound primary keys 309558826  
377065541 https://github.com/simonw/datasette/issues/190#issuecomment-377065541 https://api.github.com/repos/simonw/datasette/issues/190 MDEyOklzc3VlQ29tbWVudDM3NzA2NTU0MQ== simonw 9599 2018-03-28T22:58:52Z 2018-03-28T22:58:52Z OWNER

This is because the SQL we are using here is:

select * from compound_primary_key where "pk1" > "d" and "pk2" > "v" order by pk1, pk2 limit 101

This is incorrect. The correct SQL syntax (according to the example on https://www.sqlite.org/rowvalue.html#scrolling_window_queries ) is:

select * from compound_primary_key where ("pk1", "pk2") > ("d", "v") order by pk1, pk2 limit 101

BUT... 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

The 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.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Keyset pagination doesn't work correctly for compound primary keys 309558826  
377055663 https://github.com/simonw/datasette/issues/189#issuecomment-377055663 https://api.github.com/repos/simonw/datasette/issues/189 MDEyOklzc3VlQ29tbWVudDM3NzA1NTY2Mw== simonw 9599 2018-03-28T22:14:53Z 2018-03-28T22:14:53Z OWNER

There is one other interesting option for auto-enabling/disabling sort: the inspect command could include data about column index presence and whether or not a column has any null values in it.

This would allow us to dynamically include a "nulls last" option but only for columns that contain at least one null.

It's quite a lot of additional engineering for a very minor feature though, so I think I'll punt on that for the moment.

We may find that the _group_count feature can benefit from column value statistics later on though.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Ability to sort (and paginate) by column 309471814  
377054358 https://github.com/simonw/datasette/issues/189#issuecomment-377054358 https://api.github.com/repos/simonw/datasette/issues/189 MDEyOklzc3VlQ29tbWVudDM3NzA1NDM1OA== simonw 9599 2018-03-28T22:09:25Z 2018-03-28T22:09:25Z OWNER

I'm tempted to put these verbose sorting options inline in the page HTML but have them in the table footer so they don't clog up the top half of the page with uninteresting links - then use JavaScript to hoik them out into a dropdown menu attached to each column header.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Ability to sort (and paginate) by column 309471814  
377050461 https://github.com/simonw/datasette/issues/189#issuecomment-377050461 https://api.github.com/repos/simonw/datasette/issues/189 MDEyOklzc3VlQ29tbWVudDM3NzA1MDQ2MQ== simonw 9599 2018-03-28T21:55:14Z 2018-03-28T22:06:30Z OWNER

I think there are actually four kinds of sort order we need to support;

  • ascending
  • descending
  • ascending, nulls last
  • descending, nulls last

It looks like [-blah] is a valid SQLite table name, so mark I descending with a hyphen prefix isn't good.

Instead, maybe this:

?_sort_asc=col1&_sort_desc_nulls_last=col2
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Ability to sort (and paginate) by column 309471814  
377052634 https://github.com/simonw/datasette/issues/189#issuecomment-377052634 https://api.github.com/repos/simonw/datasette/issues/189 MDEyOklzc3VlQ29tbWVudDM3NzA1MjYzNA== simonw 9599 2018-03-28T22:03:16Z 2018-03-28T22:03:16Z OWNER

In terms of user interface: the obvious place to put this is as a drop down menu on the column headers.

This also means the UI can support combined sort orders. Assuming you are already sorted by county descending and you select the candidate column header, the options could be:

  • sort all by candidate
  • sort all by candidate, descending
  • sort by county descending, then by candidate
  • sort by county descending, then by candidate descending
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Ability to sort (and paginate) by column 309471814  
377051018 https://github.com/simonw/datasette/issues/189#issuecomment-377051018 https://api.github.com/repos/simonw/datasette/issues/189 MDEyOklzc3VlQ29tbWVudDM3NzA1MTAxOA== simonw 9599 2018-03-28T21:57:20Z 2018-03-28T22:00:17Z OWNER

I'd like to continue to support _next=token pagination even for custom sort orders.

To do that I should include rowid (or general primary key) as the tie breaker on all sorts so I can incorporate that it into the _next= token.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Ability to sort (and paginate) by column 309471814  
377049625 https://github.com/simonw/datasette/issues/189#issuecomment-377049625 https://api.github.com/repos/simonw/datasette/issues/189 MDEyOklzc3VlQ29tbWVudDM3NzA0OTYyNQ== simonw 9599 2018-03-28T21:52:05Z 2018-03-28T21:52:05Z OWNER

This is a better pattern as you don't have to pick a minimum value:

ORDER BY CASE WHEN SOMECOL IS NULL THEN 1 ELSE 0 END, SOMECOL
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Ability to sort (and paginate) by column 309471814  
376986668 https://github.com/simonw/datasette/issues/189#issuecomment-376986668 https://api.github.com/repos/simonw/datasette/issues/189 MDEyOklzc3VlQ29tbWVudDM3Njk4NjY2OA== simonw 9599 2018-03-28T18:21:53Z 2018-03-28T18:21:53Z OWNER

Might have to do something special to get sort-by-nulls-last: https://stackoverflow.com/questions/12503120/how-to-do-nulls-last-in-sqlite

order by ifnull(column_name, -999999)

Would need to figure out a smart way to get the default value - maybe by running a min() or max() against the column first?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Ability to sort (and paginate) by column 309471814  
376983741 https://github.com/simonw/datasette/issues/189#issuecomment-376983741 https://api.github.com/repos/simonw/datasette/issues/189 MDEyOklzc3VlQ29tbWVudDM3Njk4Mzc0MQ== simonw 9599 2018-03-28T18:12:35Z 2018-03-28T18:12:35Z OWNER

I think this can work with a ?_sort=xxx parameter - and ?_sort=-xxx to sort in the opposite direction.

I'd like to support "sort by X descending, then by Y ascending if there are dupes for X" as well. Two ways that could work:

?_sort=-xxx,yyy

Or...

?_sort=-xxx&_sort=yyy

The second option is probably better in that it makes it easier for columns to have a comma in their name.

Is it possible for a SQLite column to start with a - character?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Ability to sort (and paginate) by column 309471814  
376981291 https://github.com/simonw/datasette/issues/189#issuecomment-376981291 https://api.github.com/repos/simonw/datasette/issues/189 MDEyOklzc3VlQ29tbWVudDM3Njk4MTI5MQ== simonw 9599 2018-03-28T18:06:08Z 2018-03-28T18:06:08Z OWNER

Given how unlikely it is that this will pose a real problem I think I like option 1: enable sort-by-column by default for all tables, then allow power users to instead switch to explicit enabling of the functionality in their metadata.json if they know their data is too big.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Ability to sort (and paginate) by column 309471814  

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issue_comments] (
   [html_url] TEXT,
   [issue_url] TEXT,
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [created_at] TEXT,
   [updated_at] TEXT,
   [author_association] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [issue] INTEGER REFERENCES [issues]([id])
, [performed_via_github_app] TEXT);
CREATE INDEX [idx_issue_comments_issue]
                ON [issue_comments] ([issue]);
CREATE INDEX [idx_issue_comments_user]
                ON [issue_comments] ([user]);
Powered by Datasette · Queries took 845.85ms · About: github-to-sqlite
  • Sort ascending
  • Sort descending
  • Facet by this
  • Hide this column
  • Show all columns
  • Show not-blank rows