summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
authorbeenje <beenje@gmail.org>2016-04-11 23:15:35 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-06-01 17:20:41 -0400
commitef0da7eb66d173a487adbee96311bf4996da0556 (patch)
treeba87f3817e332b17a9bf958b602bc99a867afe42 /lib/sqlalchemy/dialects/postgresql/base.py
parenta8e7bb8782ca8fd858ac036082104b4ac2991cfc (diff)
downloadsqlalchemy-ef0da7eb66d173a487adbee96311bf4996da0556.tar.gz
Add postgresql_tablespace option on Index
This complements the same-named parameter available on Table. Fixes: #3720 Change-Id: I56e081e2a551f37c3f392ca4b301c9ef82b94e59 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/233
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index fe3d29450..136cb1b28 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -414,6 +414,16 @@ keyword argument::
.. versionadded:: 1.0.6
+PostgreSQL allows to define the tablespace in which to create the index.
+The tablespace can be specified on :class:`.Index` using the
+``postgresql_tablespace`` keyword argument::
+
+ Index('my_index', my_table.c.data, postgresql_tablespace='my_tablespace')
+
+.. versionadded:: 1.1
+
+Note that the same option is available on :class:`.Table` as well.
+
.. _postgresql_index_concurrently:
Indexes with CONCURRENTLY
@@ -482,6 +492,8 @@ dialect in conjunction with the :class:`.Table` construct:
Table("some_table", metadata, ..., postgresql_tablespace='some_tablespace')
+ The above option is also available on the :class:`.Index` construct.
+
* ``ON COMMIT``::
Table("some_table", metadata, ..., postgresql_on_commit='PRESERVE ROWS')
@@ -1294,6 +1306,11 @@ class PGDDLCompiler(compiler.DDLCompiler):
['%s = %s' % storage_parameter
for storage_parameter in withclause.items()]))
+ tablespace_name = index.dialect_options['postgresql']['tablespace']
+
+ if tablespace_name:
+ text += " TABLESPACE %s" % preparer.quote(tablespace_name)
+
whereclause = index.dialect_options["postgresql"]["where"]
if whereclause is not None:
@@ -1631,7 +1648,8 @@ class PGDialect(default.DefaultDialect):
"where": None,
"ops": {},
"concurrently": False,
- "with": {}
+ "with": {},
+ "tablespace": None
}),
(schema.Table, {
"ignore_search_path": False,