html_url,issue_url,id,node_id,user,user_label,created_at,updated_at,author_association,body,reactions,issue,issue_label,performed_via_github_app https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968380387,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968380387,IC_kwDOCGYnMM45uE_j,9599,simonw,2021-11-14T22:55:56Z,2021-11-14T22:55:56Z,OWNER,"OK, this should fix it.","{""total_count"": 1, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 1, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index, https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968371112,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968371112,IC_kwDOCGYnMM45uCuo,9599,simonw,2021-11-14T21:57:43Z,2021-11-14T22:21:31Z,OWNER,"`create_index(..., find_unique_name=)` is good. Default to false. `index_foreign_keys` can set it to true.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index, https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968361671,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968361671,IC_kwDOCGYnMM45uAbH,9599,simonw,2021-11-14T20:54:53Z,2021-11-14T21:01:14Z,OWNER,"I'm leaning towards `table.create_index(columns, ignore_existing_name=True)` now. Or `resolve_existing_name` - or `skip_existing_name`? ""ignore"" sounds like it might not create the index if the name exists, but we want to still create the index but pick a new name.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index, https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968362285,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968362285,IC_kwDOCGYnMM45uAkt,9599,simonw,2021-11-14T20:59:44Z,2021-11-14T20:59:44Z,OWNER,I think I'll attempt to create the index and re-try if it fails with that error.,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index, https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968362214,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968362214,IC_kwDOCGYnMM45uAjm,9599,simonw,2021-11-14T20:59:15Z,2021-11-14T20:59:15Z,OWNER,"How to figure out if an index name is already in use? `PRAGMA index_list(t)` requires a table name. This does it: ```sql SELECT name FROM sqlite_master WHERE type = 'index'; ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index, https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968361409,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968361409,IC_kwDOCGYnMM45uAXB,9599,simonw,2021-11-14T20:52:55Z,2021-11-14T20:52:55Z,OWNER,"Looking at the method signature: https://github.com/simonw/sqlite-utils/blob/92aa5c9c5d26b0889c8c3d97c76a908d5f8af211/sqlite_utils/db.py#L1518-L1524 `if_not_exists` just adds a `IF NOT EXISTS` clause here: https://github.com/simonw/sqlite-utils/blob/92aa5c9c5d26b0889c8c3d97c76a908d5f8af211/sqlite_utils/db.py#L1549-L1561","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index, https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968361285,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968361285,IC_kwDOCGYnMM45uAVF,9599,simonw,2021-11-14T20:51:57Z,2021-11-14T20:51:57Z,OWNER,"SQLite will happily create multiple identical indexes on a table, using more disk space each time: ```pycon >>> import sqlite_utils >>> db = sqlite_utils.Database(""dupes.db"") >>> db[""t""].insert_all({""id"": i} for i in range(10000)) # dupes.db is 98304 bytes >>> db[""t""].create_index([""id""])
# dupes.db is 204800 bytes >>> db[""t""].indexes [Index(seq=0, name='idx_t_id', unique=0, origin='c', partial=0, columns=['id'])] >>> db[""t""].create_index([""id""], index_name=""t_idx_t_id_2"")
# 311296 bytes >>> db[""t""].create_index([""id""], index_name=""t_idx_t_id_3"")
# 417792 bytes >>> db.vacuum() # Still 417792 bytes ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index, https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968360538,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968360538,IC_kwDOCGYnMM45uAJa,9599,simonw,2021-11-14T20:46:56Z,2021-11-14T20:46:56Z,OWNER,"I'm tempted to not provide an opt-out option either: if you call `table.create_index(...)` without specifying an index name I think the tool should create the index for you, quietly picking an index name that works. But... it feels wasteful to create an index that exactly duplicates an existing index. Would SQLite even let you do that or would it notice and NOT double the amount of disk space used for that index?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index, https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968360387,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968360387,IC_kwDOCGYnMM45uAHD,9599,simonw,2021-11-14T20:45:44Z,2021-11-14T20:45:44Z,OWNER,"What would such an option be called? Some options: - `table.create_index([fk.column], force=True)` - not obvious what `force` means here - `table.create_index([fk.column], ignore_existing_name=True)` - not obvious what `ignore` means here - `table.create_index([fk.column], pick_unique_name=True)` - bit verbose If the user doesn't pass in an explicit name it seems like their intent is ""just create me the index, I don't care what name you use"" - so actually perhaps the default behaviour here should be to pick a new unique name if that name is already in use. Then maybe there should be an option to disable that - some options there: - `table.create_index([fk.column], error_on_existing_index_name=True)` - too verbose - `table.create_index([fk.column], force=False)` - not clear what `force` means ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index, https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968359868,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968359868,IC_kwDOCGYnMM45t_-8,9599,simonw,2021-11-14T20:41:42Z,2021-11-14T20:41:42Z,OWNER,"The ""index idx_generators_eia860_report_date already exists"" error suggests that the problem here is actually one of an index name collision. ```python table.create_index([fk.column]) ``` This will derive a name for the index automatically from the name of the table and the name of the passed in columns: https://github.com/simonw/sqlite-utils/blob/92aa5c9c5d26b0889c8c3d97c76a908d5f8af211/sqlite_utils/db.py#L1536-L1539 So perhaps `.create_index()` should grow an extra option that creates the index even if the name already exists, by finding a new name.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index, https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968359137,https://api.github.com/repos/simonw/sqlite-utils/issues/335,968359137,IC_kwDOCGYnMM45t_zh,9599,simonw,2021-11-14T20:37:00Z,2021-11-14T20:37:00Z,OWNER,This is strange - the code already checks that an index doesn't exist before attempting to create it: https://github.com/simonw/sqlite-utils/blob/92aa5c9c5d26b0889c8c3d97c76a908d5f8af211/sqlite_utils/db.py#L893-L902,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1042569687,sqlite-utils index-foreign-keys fails due to pre-existing index,