create_index now works with columns with spaces, closes #85

This commit is contained in:
Simon Willison 2020-02-10 21:13:15 -08:00
commit 6f3cb2c106
2 changed files with 10 additions and 10 deletions

View file

@ -625,12 +625,12 @@ class Table(Queryable):
self.name.replace(" ", "_"), "_".join(columns)
)
sql = """
CREATE {unique}INDEX {if_not_exists}{index_name}
ON {table_name} ({columns});
CREATE {unique}INDEX {if_not_exists}[{index_name}]
ON [{table_name}] ({columns});
""".format(
index_name=index_name,
table_name=self.name,
columns=", ".join(columns),
columns=", ".join("[{}]".format(c) for c in columns),
unique="UNIQUE " if unique else "",
if_not_exists="IF NOT EXISTS " if if_not_exists else "",
)