html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,issue,performed_via_github_app https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850764253,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850764253,MDEyOklzc3VlQ29tbWVudDg1MDc2NDI1Mw==,9599,2021-05-29T03:57:54Z,2021-05-29T03:57:54Z,OWNER,"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`. This won't work: ```python db[""ny_times_us_counties""].create_index([""date desc""], desc=True) ``` Because we need to be able to create compound indexes with columns with different directions - for example: ```sql create index idx_age_desc_name on dogs (age desc, name) ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850764594,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850764594,MDEyOklzc3VlQ29tbWVudDg1MDc2NDU5NA==,9599,2021-05-29T04:00:54Z,2021-05-29T04:00:54Z,OWNER,"A few options: ```python db[""dogs""].create_index([(""age"", ""desc""), ""name""]) db[""dogs""].create_index([desc(""age""), ""name""]) db[""dogs""].create_index([db.desc(""age""), ""name""]) ``` The first option uses an optional tuple. The second two use a `desc()` function - the question is where should that live? `sqlite_utils.desc(column)` or `db.desc(column)` are both options. I don't like using the term `desc()` for ""descending index"" though - it feels like it should mean something more broad.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850764655,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850764655,MDEyOklzc3VlQ29tbWVudDg1MDc2NDY1NQ==,9599,2021-05-29T04:01:41Z,2021-05-29T04:01:41Z,OWNER,"Maybe: ```python db[""dogs""].create_index([db.descending_index(""age""), ""name""]) ``` It's a little verbose but it's for a relatively rare activity and it does make it very clear what is going on.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850764700,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850764700,MDEyOklzc3VlQ29tbWVudDg1MDc2NDcwMA==,9599,2021-05-29T04:02:10Z,2021-05-29T04:02:10Z,OWNER,"I could use `db.desc_index(""age"")` to match SQLite SQL syntax, which uses `desc` and not `descending`.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850765050,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850765050,MDEyOklzc3VlQ29tbWVudDg1MDc2NTA1MA==,9599,2021-05-29T04:05:24Z,2021-05-29T04:05:40Z,OWNER,"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 ```sh sqlite-utils create-index mydb.db mytable col1 [col2...] ``` Even harder to decide how to add a descending option to this. Maybe like this? ```sh sqlite-utils create-index mydb.db mytable --direction col1 asc --direction col2 desc ``` It'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. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850765291,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850765291,MDEyOklzc3VlQ29tbWVudDg1MDc2NTI5MQ==,9599,2021-05-29T04:07:48Z,2021-05-29T04:08:21Z,OWNER,"For the CLI version I could say that you can use a `-` prefix to specify reverse direction: ```sh sqlite-utils create-index mydb.db dogs -age name ``` No, that doesn't work - it could get confused with a command-line flag. I guess you could do this: ``` sqlite-utils create-index mydb.db dogs ""-age"" name ``` This 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.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850765450,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850765450,MDEyOklzc3VlQ29tbWVudDg1MDc2NTQ1MA==,9599,2021-05-29T04:09:13Z,2021-05-29T04:09:13Z,OWNER,"Decisions: for the Python API I'm going with `db.DescIndex(""column"")` as the way to do this. For the CLI I'm going to do the ""-age"" thing.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850766335,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850766335,MDEyOklzc3VlQ29tbWVudDg1MDc2NjMzNQ==,9599,2021-05-29T04:18:19Z,2021-05-29T04:18:19Z,OWNER,"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: ``` (Pdb) fresh_db.execute(""select * from sqlite_master where type = 'index'"").fetchall() [('index', 'idx_dogs_age_name', 'dogs', 3, 'CREATE INDEX [idx_dogs_age_name]\n ON [dogs] ([age] desc, [name])')] (Pdb) fresh_db.execute(""PRAGMA index_info('idx_dogs_age_name')"").fetchall() [(0, 2, 'age'), (1, 0, 'name')] (Pdb) fresh_db.execute(""PRAGMA index_info('idx_dogs_age_name')"").description (('seqno', None, None, None, None, None, None), ('cid', None, None, None, None, None, None), ('name', None, None, None, None, None, None)) (Pdb) dogs.indexes [Index(seq=0, name='idx_dogs_age_name', unique=0, origin='c', partial=0, columns=['age', 'name'])] ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850766552,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850766552,MDEyOklzc3VlQ29tbWVudDg1MDc2NjU1Mg==,9599,2021-05-29T04:20:40Z,2021-05-29T04:24:01Z,OWNER,"`PRAGMA index_xinfo(table)` DOES return that data: ``` (Pdb) [c[0] for c in fresh_db.execute(""PRAGMA index_xinfo('idx_dogs_age_name')"").description] ['seqno', 'cid', 'name', 'desc', 'coll', 'key'] (Pdb) fresh_db.execute(""PRAGMA index_xinfo('idx_dogs_age_name')"").fetchall() [(0, 2, 'age', 1, 'BINARY', 1), (1, 0, 'name', 0, 'BINARY', 1), (2, -1, None, 0, 'BINARY', 0)] ``` See https://sqlite.org/pragma.html#pragma_index_xinfo Example output: https://covid-19.datasettes.com/covid?sql=select+*+from+pragma_index_xinfo%28%27idx_ny_times_us_counties_date%27%29","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850767210,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850767210,MDEyOklzc3VlQ29tbWVudDg1MDc2NzIxMA==,9599,2021-05-29T04:26:26Z,2021-05-29T04:28:31Z,OWNER,It's weird having to use `Database.DescIndex` - I'm going to put `DescIndex` in `sqlite_utils.db` directly and let people import it.,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850768315,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850768315,MDEyOklzc3VlQ29tbWVudDg1MDc2ODMxNQ==,9599,2021-05-29T04:39:33Z,2021-05-29T04:39:33Z,OWNER,"This doesn't work: ``` sqlite-utils create-index mydb.db dogs ""-age"" name ``` But this does: ``` sqlite-utils create-index mydb.db dogs -- -age name ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187, https://github.com/simonw/sqlite-utils/issues/260#issuecomment-850769067,https://api.github.com/repos/simonw/sqlite-utils/issues/260,850769067,MDEyOklzc3VlQ29tbWVudDg1MDc2OTA2Nw==,9599,2021-05-29T04:48:10Z,2021-05-29T04:48:10Z,OWNER,"I confirmed and it's possible to have a SQLite column with a hyphen at the start, confirmed using: ``` % sqlite-utils create-table demo.db demo -- id integer name text -blah integer % sqlite-utils tables --schema demo.db -t table schema ------- --------------------- demo CREATE TABLE [demo] ( [id] INTEGER, [name] TEXT, [-blah] INTEGER ) ``` ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",906330187,