summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-06-19 13:45:01 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-06-19 13:45:01 -0400
commit99ceed3e55e87c7aca9898359e68c90ecee7965c (patch)
tree3b8b0ff56e8c3305f4974bb52e88c8cc64a462de /lib/sqlalchemy/dialects/postgresql/base.py
parenta1b6e9f324eec04ff69f2ac5347ad3df5b931dd5 (diff)
parentaf19435b9c1cec28d0ac93aa832b45601af51597 (diff)
downloadsqlalchemy-99ceed3e55e87c7aca9898359e68c90ecee7965c.tar.gz
Merge remote-tracking branch 'origin/pr/179' into pr179
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py39
1 files changed, 36 insertions, 3 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index bc1c3614e..b46c65335 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -401,6 +401,15 @@ The value passed to the keyword argument will be simply passed through to the
underlying CREATE INDEX command, so it *must* be a valid index type for your
version of PostgreSQL.
+Index Storage Parameters
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+PostgreSQL allows storage parameters to be set on indexes. The storage
+parameters available depend on the index method used by the index. Storage
+parameters can be specified on :class:`.Index` using the ``postgresql_with``
+keyword argument::
+
+ Index('my_index', my_table.c.data, postgresql_with={"fillfactor": 50})
.. _postgresql_index_concurrently:
@@ -1592,6 +1601,13 @@ class PGDDLCompiler(compiler.DDLCompiler):
])
)
+ withclause = index.dialect_options['postgresql']['with']
+
+ if withclause:
+ text += " WITH (%s)" % (', '.join(
+ ['%s = %s' % storage_parameter
+ for storage_parameter in withclause.items()]))
+
whereclause = index.dialect_options["postgresql"]["where"]
if whereclause is not None:
@@ -1921,6 +1937,7 @@ class PGDialect(default.DefaultDialect):
"where": None,
"ops": {},
"concurrently": False,
+ "with": {}
}),
(schema.Table, {
"ignore_search_path": False,
@@ -2609,7 +2626,8 @@ class PGDialect(default.DefaultDialect):
SELECT
i.relname as relname,
ix.indisunique, ix.indexprs, ix.indpred,
- a.attname, a.attnum, NULL, ix.indkey%s
+ a.attname, a.attnum, NULL, ix.indkey%s,
+ i.reloptions, am.amname
FROM
pg_class t
join pg_index ix on t.oid = ix.indrelid
@@ -2617,6 +2635,9 @@ class PGDialect(default.DefaultDialect):
left outer join
pg_attribute a
on t.oid = a.attrelid and %s
+ left outer join
+ pg_am am
+ on i.relam = am.oid
WHERE
t.relkind IN ('r', 'v', 'f', 'm')
and t.oid = :table_oid
@@ -2636,7 +2657,8 @@ class PGDialect(default.DefaultDialect):
SELECT
i.relname as relname,
ix.indisunique, ix.indexprs, ix.indpred,
- a.attname, a.attnum, c.conrelid, ix.indkey::varchar
+ a.attname, a.attnum, c.conrelid, ix.indkey::varchar,
+ i.reloptions, am.amname
FROM
pg_class t
join pg_index ix on t.oid = ix.indrelid
@@ -2649,6 +2671,9 @@ class PGDialect(default.DefaultDialect):
on (ix.indrelid = c.conrelid and
ix.indexrelid = c.conindid and
c.contype in ('p', 'u', 'x'))
+ left outer join
+ pg_am am
+ on i.relam = am.oid
WHERE
t.relkind IN ('r', 'v', 'f', 'm')
and t.oid = :table_oid
@@ -2665,7 +2690,7 @@ class PGDialect(default.DefaultDialect):
sv_idx_name = None
for row in c.fetchall():
- idx_name, unique, expr, prd, col, col_num, conrelid, idx_key = row
+ idx_name, unique, expr, prd, col, col_num, conrelid, idx_key, options, amname = row
if expr:
if idx_name != sv_idx_name:
@@ -2691,6 +2716,10 @@ class PGDialect(default.DefaultDialect):
index['unique'] = unique
if conrelid is not None:
index['duplicates_constraint'] = idx_name
+ if options:
+ index['options'] = dict([option.split("=") for option in options])
+ if amname and amname != 'btree':
+ index['amname'] = amname
result = []
for name, idx in indexes.items():
@@ -2701,6 +2730,10 @@ class PGDialect(default.DefaultDialect):
}
if 'duplicates_constraint' in idx:
entry['duplicates_constraint'] = idx['duplicates_constraint']
+ if 'options' in idx:
+ entry.setdefault('dialect_options', {})["postgresql_with"] = idx['options']
+ if 'amname' in idx:
+ entry.setdefault('dialect_options', {})["postgresql_using"] = idx['amname']
result.append(entry)
return result