summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authordonkopotamus <derek.harland@finq.co.nz>2014-01-17 10:46:16 +1300
committerdonkopotamus <derek.harland@finq.co.nz>2014-01-17 10:46:16 +1300
commit35935489608c6a896790ed0c51c3ea4b4eb6186f (patch)
treecca83bc60558be06768f9786974ab31f45e35397 /lib/sqlalchemy
parent1de7259093b1a49438ab26ca9661fd6023244afe (diff)
downloadsqlalchemy-35935489608c6a896790ed0c51c3ea4b4eb6186f.tar.gz
Support mssql_clustered option on UniqueConstraint (plus docs and test)
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index 213e00d79..c024b6230 100644
--- a/lib/sqlalchemy/dialects/mssql/base.py
+++ b/lib/sqlalchemy/dialects/mssql/base.py
@@ -107,8 +107,8 @@ Clustered Index Support
-----------------------
The MSSQL dialect supports clustered indexes (and primary keys) via the
-``mssql_clustered`` option. This option is available to :class:`.Index`
-and :class:`.PrimaryKeyConstraint`.
+``mssql_clustered`` option. This option is available to :class:`.Index`,
+:class:`.UniqueConstraint`. and :class:`.PrimaryKeyConstraint`.
To generate a clustered index::
@@ -129,7 +129,16 @@ which will render the table, for example, as::
CREATE TABLE my_table (x INTEGER NOT NULL, y INTEGER NOT NULL, PRIMARY KEY CLUSTERED (x, y))
-.. versionadded:: 0.9
+Similarly, we can generate a clustered unique constraint using::
+
+ Table('my_table', metadata,
+ Column('x', ...),
+ Column('y', ...),
+ PrimaryKeyConstraint("x"),
+ UniqueConstraint("y", mssql_clustered=True),
+ )
+
+ .. versionadded:: 0.9
MSSQL-Specific Index Options
-----------------------------
@@ -1055,7 +1064,23 @@ class MSDDLCompiler(compiler.DDLCompiler):
text += "CLUSTERED "
text += "(%s)" % ', '.join(self.preparer.quote(c.name)
- for c in constraint)
+ for c in constraint)
+ text += self.define_constraint_deferrability(constraint)
+ return text
+
+ def visit_unique_constraint(self, constraint):
+ text = ""
+ if constraint.name is not None:
+ text += "CONSTRAINT %s " % \
+ self.preparer.format_constraint(constraint)
+ text += "UNIQUE "
+
+ # support clustered option
+ if constraint.kwargs.get("mssql_clustered"):
+ text += "CLUSTERED "
+
+ text += "(%s)" % ', '.join(self.preparer.quote(c.name)
+ for c in constraint)
text += self.define_constraint_deferrability(constraint)
return text