summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-10-02 17:17:46 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-10-02 17:17:46 -0400
commitbf2f3595d07002d56c77b329387932d4d27e3c45 (patch)
tree06f68edb7131347e9cb2350bddbb5fd9f2a9cd5e /lib/sqlalchemy/dialects/postgresql
parent4f1321c3e97f9bb1c92b378452a7810874927c71 (diff)
downloadsqlalchemy-bf2f3595d07002d56c77b329387932d4d27e3c45.tar.gz
- Added "postgresql_using" argument to Index(), produces
USING clause to specify index implementation for PG. [ticket:2290]. Thanks to Ryan P. Kelly for the patch.
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 8c3babd31..b3be7bc99 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -141,6 +141,20 @@ the :class:`.Column`, i.e. the name used to access it from the ``.c`` collection
of :class:`.Table`, which can be configured to be different than the actual
name of the column as expressed in the database.
+Index Types
+^^^^^^^^^^^^
+
+PostgreSQL provides several index types: B-Tree, Hash, GiST, and GIN, as well as
+the ability for users to create their own (see
+http://www.postgresql.org/docs/8.3/static/indexes-types.html). These can be
+specified on :class:`.Index` using the ``postgresql_using`` keyword argument::
+
+ Index('my_index', my_table.c.data, postgresql_using='gin')
+
+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.
+
"""
import re
@@ -629,11 +643,18 @@ class PGDDLCompiler(compiler.DDLCompiler):
if index.unique:
text += "UNIQUE "
ops = index.kwargs.get('postgresql_ops', {})
- text += "INDEX %s ON %s (%s)" \
- % (
+ text += "INDEX %s ON %s " % (
preparer.quote(
self._index_identifier(index.name), index.quote),
- preparer.format_table(index.table),
+ preparer.format_table(index.table)
+ )
+
+ if 'postgresql_using' in index.kwargs:
+ using = index.kwargs['postgresql_using']
+ text += "USING %s " % preparer.quote(using, index.quote)
+
+ text += "(%s)" \
+ % (
', '.join([
preparer.format_column(c) +
(c.key in ops and (' ' + ops[c.key]) or '')