home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

6 rows where issue = 564579430 and user = 9599 sorted by updated_at descending

✖
✖
✖

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: reactions, created_at (date), updated_at (date)

user 1

  • simonw · 6 ✖

issue 1

  • Problem with square bracket in CSV column name · 6 ✖

author_association 1

  • OWNER 6
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions issue performed_via_github_app
591770623 https://github.com/simonw/sqlite-utils/issues/86#issuecomment-591770623 https://api.github.com/repos/simonw/sqlite-utils/issues/86 MDEyOklzc3VlQ29tbWVudDU5MTc3MDYyMw== simonw 9599 2020-02-27T04:12:39Z 2020-02-27T04:12:39Z OWNER

I pushed a branch with my experiment in it, but I'm going to fix this by throwing an error on [ or ] in a column name instead - I won't implement the changes from that branch.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Problem with square bracket in CSV column name 564579430  
586729798 https://github.com/simonw/sqlite-utils/issues/86#issuecomment-586729798 https://api.github.com/repos/simonw/sqlite-utils/issues/86 MDEyOklzc3VlQ29tbWVudDU4NjcyOTc5OA== simonw 9599 2020-02-16T17:11:02Z 2020-02-16T17:11:02Z OWNER

I filed a bug in the Python issue tracker here: https://bugs.python.org/issue39652

{
    "total_count": 2,
    "+1": 2,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Problem with square bracket in CSV column name 564579430  
586676856 https://github.com/simonw/sqlite-utils/issues/86#issuecomment-586676856 https://api.github.com/repos/simonw/sqlite-utils/issues/86 MDEyOklzc3VlQ29tbWVudDU4NjY3Njg1Ng== simonw 9599 2020-02-16T07:20:34Z 2020-02-16T07:20:34Z OWNER

I'm not sure what to do about this one.

I can't fix it: this bug in Python's sqlite3 module means that even if I write a database out with column names that include [] I won't be able to read them back again.

So... I could do one of the following:

  • Throw an error if a column name includes those characters. That's my preferred option I think.
  • Automatically replace [ in column names with ( and ] with )
  • Do the automatic replacement but show a user-visible warning when I do it
  • Throw an error, but give the user an option to run with e.g. --fix-column-names which applies that automatic fix.

Since this is likely to be an incredibly rare edge-case I think I'd rather minimize the amount of code that deals with it, so my preferred option is to just throw that error and stop.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Problem with square bracket in CSV column name 564579430  
586676640 https://github.com/simonw/sqlite-utils/issues/86#issuecomment-586676640 https://api.github.com/repos/simonw/sqlite-utils/issues/86 MDEyOklzc3VlQ29tbWVudDU4NjY3NjY0MA== simonw 9599 2020-02-16T07:16:31Z 2020-02-16T07:16:31Z OWNER

There's something weird about this. I created a test database file like so: sqlite3 /tmp/demo.db <<EOF BEGIN TRANSACTION; CREATE TABLE "data" ( "MTU (CET)" TEXT, "Day-ahead Price [EUR/MWh]" TEXT ); INSERT INTO "data" VALUES('01.01.2016 00:00 - 01.01.2016 01:00','23.86'); COMMIT; EOF Then confirmed that it works as expected in SQLite: $ sqlite3 /tmp/demo.db SQLite version 3.24.0 2018-06-04 14:10:15 Enter ".help" for usage hints. sqlite> .schema CREATE TABLE IF NOT EXISTS "data" ( "MTU (CET)" TEXT, "Day-ahead Price [EUR/MWh]" TEXT ); sqlite> .headers on sqlite> select * from data; MTU (CET)|Day-ahead Price [EUR/MWh] 01.01.2016 00:00 - 01.01.2016 01:00|23.86 sqlite> BUT... if I open the same database in Python, something weird happens: In [1]: import sqlite3 In [2]: conn = sqlite3.connect("/tmp/demo.db") In [3]: cursor = conn.cursor() In [4]: cursor.execute("select * from data") Out[4]: <sqlite3.Cursor at 0x10c70a0a0> In [5]: cursor.fetchall() Out[5]: [('01.01.2016 00:00 - 01.01.2016 01:00', '23.86')] In [6]: cursor.description Out[6]: (('MTU (CET)', None, None, None, None, None, None), ('Day-ahead Price', None, None, None, None, None, None)) In [7]: conn.row_factory = sqlite3.Row In [8]: cursor = conn.cursor() In [9]: cursor.execute("select * from data") Out[9]: <sqlite3.Cursor at 0x10c7a8490> In [10]: row = cursor.fetchall() In [12]: row Out[12]: <sqlite3.Row at 0x10c3fe670> In [15]: row.keys() Out[15]: ['MTU (CET)', 'Day-ahead Price'] Note that in cursor.description AND in row.keys() above the second column is displayed as 'Day-ahead Price' - when we would expect it to be displayed as Day-ahead Price [EUR/MWh]

So.... it looks like there may be a bug in Python's sqlite3 module where columns with square braces in them have that portion of the name stripped out!

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Problem with square bracket in CSV column name 564579430  
586662404 https://github.com/simonw/sqlite-utils/issues/86#issuecomment-586662404 https://api.github.com/repos/simonw/sqlite-utils/issues/86 MDEyOklzc3VlQ29tbWVudDU4NjY2MjQwNA== simonw 9599 2020-02-16T02:43:12Z 2020-02-16T02:43:12Z OWNER

https://stackoverflow.com/a/22694438 looks like the answer:

When using square brackets, it is not possible to have these characters in the identifier.

When using double quotes, you can escape them in the name by doubling them:

CREATE TABLE "hello ""world"""(key INTEGER PRIMARY KEY);

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Problem with square bracket in CSV column name 564579430  
586661934 https://github.com/simonw/sqlite-utils/issues/86#issuecomment-586661934 https://api.github.com/repos/simonw/sqlite-utils/issues/86 MDEyOklzc3VlQ29tbWVudDU4NjY2MTkzNA== simonw 9599 2020-02-16T02:33:07Z 2020-02-16T02:33:07Z OWNER

Thanks for the example file - looks like it can be trimmed down to just these two lines to replicate the bug: csv "MTU (CET)","Day-ahead Price [EUR/MWh]" "01.01.2016 00:00 - 01.01.2016 01:00","23.86"

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Problem with square bracket in CSV column name 564579430  

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 885.288ms · About: github-to-sqlite
  • Sort ascending
  • Sort descending
  • Facet by this
  • Hide this column
  • Show all columns
  • Show not-blank rows