summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorDerek Harland <derek.harland@finq.co.nz>2013-01-14 17:02:20 +1300
committerDerek Harland <derek.harland@finq.co.nz>2013-01-14 17:02:20 +1300
commit38f765007253729f384cb2583a569194f3ee3435 (patch)
tree861b686e0f9d7c324bb8f613d49ab36b7a6bc985 /lib/sqlalchemy
parent7198abb13e464b32639d03dc5987457ba64281c4 (diff)
downloadsqlalchemy-38f765007253729f384cb2583a569194f3ee3435.tar.gz
Add mssql_ordering option for mssql dialect
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index 74d1a1320..aacc58ba8 100644
--- a/lib/sqlalchemy/dialects/mssql/base.py
+++ b/lib/sqlalchemy/dialects/mssql/base.py
@@ -943,13 +943,20 @@ class MSDDLCompiler(compiler.DDLCompiler):
if index.kwargs.get("mssql_clustered"):
text += "CLUSTERED "
+ # extend the custom ordering to the right length
+ ordering = index.kwargs.get("mssql_ordering", [])
+ if len(ordering) > len(index.columns):
+ raise ValueError("Column ordering length is incompatible with index columns")
+ elif len(ordering) < len(index.columns):
+ ordering.extend([""]*(len(index.columns) - len(ordering)))
+
text += "INDEX %s ON %s (%s)" \
% (
self._prepared_index_name(index,
include_schema=include_schema),
- preparer.format_table(index.table),
- ', '.join(preparer.quote(c.name, c.quote)
- for c in index.columns))
+ preparer.format_table(index.table),
+ ', '.join([preparer.quote(c.name, c.quote) + (" " + o if o else "")
+ for c, o in zip(index.columns, ordering)]))
return text
def visit_drop_index(self, drop):