{"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850769067", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850769067, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2OTA2Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:48:10Z", "updated_at": "2021-05-29T04:48:10Z", "author_association": "OWNER", "body": "I confirmed and it's possible to have a SQLite column with a hyphen at the start, confirmed using:\r\n```\r\n% sqlite-utils create-table demo.db demo -- id integer name text -blah integer\r\n% sqlite-utils tables --schema demo.db -t\r\ntable schema\r\n------- ---------------------\r\ndemo CREATE TABLE [demo] (\r\n [id] INTEGER,\r\n [name] TEXT,\r\n [-blah] INTEGER\r\n )\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": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850768315", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850768315, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2ODMxNQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:39:33Z", "updated_at": "2021-05-29T04:39:33Z", "author_association": "OWNER", "body": "This doesn't work:\r\n```\r\nsqlite-utils create-index mydb.db dogs \"-age\" name\r\n```\r\nBut this does:\r\n```\r\nsqlite-utils create-index mydb.db dogs -- -age name\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850767210", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850767210, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2NzIxMA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:26:26Z", "updated_at": "2021-05-29T04:28:31Z", "author_association": "OWNER", "body": "It's weird having to use `Database.DescIndex` - I'm going to put `DescIndex` in `sqlite_utils.db` directly and let people import it.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850766552", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850766552, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2NjU1Mg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:20:40Z", "updated_at": "2021-05-29T04:24:01Z", "author_association": "OWNER", "body": "`PRAGMA index_xinfo(table)` DOES return that data:\r\n```\r\n(Pdb) [c[0] for c in fresh_db.execute(\"PRAGMA index_xinfo('idx_dogs_age_name')\").description]\r\n['seqno', 'cid', 'name', 'desc', 'coll', 'key']\r\n(Pdb) fresh_db.execute(\"PRAGMA index_xinfo('idx_dogs_age_name')\").fetchall()\r\n[(0, 2, 'age', 1, 'BINARY', 1), (1, 0, 'name', 0, 'BINARY', 1), (2, -1, None, 0, 'BINARY', 0)]\r\n```\r\nSee https://sqlite.org/pragma.html#pragma_index_xinfo\r\n\r\nExample output: https://covid-19.datasettes.com/covid?sql=select+*+from+pragma_index_xinfo%28%27idx_ny_times_us_counties_date%27%29", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850766335", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850766335, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2NjMzNQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:18:19Z", "updated_at": "2021-05-29T04:18:19Z", "author_association": "OWNER", "body": "Annoyingly the `table.indexes` property won't indicate if an index is in regular or reverse order - because the SQLite `PRAGMA index_info(table)` statement doesn't indicate that either. You have to look at the `sqlite_master` index definition to tell if any of the columns are in reverse order:\r\n```\r\n(Pdb) fresh_db.execute(\"select * from sqlite_master where type = 'index'\").fetchall()\r\n[('index', 'idx_dogs_age_name', 'dogs', 3, 'CREATE INDEX [idx_dogs_age_name]\\n ON [dogs] ([age] desc, [name])')]\r\n(Pdb) fresh_db.execute(\"PRAGMA index_info('idx_dogs_age_name')\").fetchall()\r\n[(0, 2, 'age'), (1, 0, 'name')]\r\n(Pdb) fresh_db.execute(\"PRAGMA index_info('idx_dogs_age_name')\").description\r\n(('seqno', None, None, None, None, None, None), ('cid', None, None, None, None, None, None), ('name', None, None, None, None, None, None))\r\n(Pdb) dogs.indexes\r\n[Index(seq=0, name='idx_dogs_age_name', unique=0, origin='c', partial=0, columns=['age', 'name'])]\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850765450", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850765450, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2NTQ1MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:09:13Z", "updated_at": "2021-05-29T04:09:13Z", "author_association": "OWNER", "body": "Decisions: for the Python API I'm going with `db.DescIndex(\"column\")` as the way to do this.\r\n\r\nFor the CLI I'm going to do the \"-age\" thing.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850765291", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850765291, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2NTI5MQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:07:48Z", "updated_at": "2021-05-29T04:08:21Z", "author_association": "OWNER", "body": "For the CLI version I could say that you can use a `-` prefix to specify reverse direction:\r\n```sh\r\nsqlite-utils create-index mydb.db dogs -age name\r\n```\r\nNo, that doesn't work - it could get confused with a command-line flag. I guess you could do this:\r\n```\r\nsqlite-utils create-index mydb.db dogs \"-age\" name\r\n```\r\nThis does mean that if any of your column names begin with a hyphen you can't use the CLI to add indexes to them. Is that an acceptable limitation? Users can always use `sqlite-utils mydb.db \"create index ...\"` in that case.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850765050", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850765050, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2NTA1MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:05:24Z", "updated_at": "2021-05-29T04:05:40Z", "author_association": "OWNER", "body": "Need to solve this for the CLI tool too. Currently that works like this: https://sqlite-utils.datasette.io/en/stable/cli.html#creating-indexes\r\n```sh\r\nsqlite-utils create-index mydb.db mytable col1 [col2...]\r\n```\r\nEven harder to decide how to add a descending option to this. Maybe like this?\r\n```sh\r\nsqlite-utils create-index mydb.db mytable --direction col1 asc --direction col2 desc\r\n```\r\nIt's a bit gross though! We're saying here that if a single one of the columns you are creating an index for is in reverse direction you have to use `--direction` to specify each end every other index.\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": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850764700", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850764700, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2NDcwMA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:02:10Z", "updated_at": "2021-05-29T04:02:10Z", "author_association": "OWNER", "body": "I could use `db.desc_index(\"age\")` to match SQLite SQL syntax, which uses `desc` and not `descending`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850764655", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850764655, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2NDY1NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:01:41Z", "updated_at": "2021-05-29T04:01:41Z", "author_association": "OWNER", "body": "Maybe:\r\n```python\r\ndb[\"dogs\"].create_index([db.descending_index(\"age\"), \"name\"])\r\n```\r\nIt's a little verbose but it's for a relatively rare activity and it does make it very clear what is going on.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850764594", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850764594, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2NDU5NA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T04:00:54Z", "updated_at": "2021-05-29T04:00:54Z", "author_association": "OWNER", "body": "A few options:\r\n```python\r\ndb[\"dogs\"].create_index([(\"age\", \"desc\"), \"name\"])\r\n\r\ndb[\"dogs\"].create_index([desc(\"age\"), \"name\"])\r\n\r\ndb[\"dogs\"].create_index([db.desc(\"age\"), \"name\"])\r\n```\r\nThe first option uses an optional tuple. The second two use a `desc()` function - the question is where should that live? \r\n\r\n`sqlite_utils.desc(column)` or `db.desc(column)` are both options.\r\n\r\nI don't like using the term `desc()` for \"descending index\" though - it feels like it should mean something more broad.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850764253", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/260", "id": 850764253, "node_id": "MDEyOklzc3VlQ29tbWVudDg1MDc2NDI1Mw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-05-29T03:57:54Z", "updated_at": "2021-05-29T03:57:54Z", "author_association": "OWNER", "body": "The problem here is differentiating between a column with the name `date desc` and wanting to create a descending index on a column called `date`.\r\n\r\nThis won't work:\r\n```python\r\ndb[\"ny_times_us_counties\"].create_index([\"date desc\"], desc=True)\r\n```\r\nBecause we need to be able to create compound indexes with columns with different directions - for example:\r\n```sql\r\ncreate index idx_age_desc_name on dogs (age desc, name)\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 906330187, "label": "Support creating descending order indexes"}, "performed_via_github_app": null}