summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/introspection.py
diff options
context:
space:
mode:
authorAkshesh <aksheshdoshi@gmail.com>2016-08-08 10:29:08 +0530
committerTim Graham <timograham@gmail.com>2016-08-12 16:58:40 -0400
commit2f19306a125a9253d99b35b276d932e8e24d4e6f (patch)
tree6c505535f15218b2ea0fd57e7d4ae97976662daa /django/db/backends/postgresql/introspection.py
parent72d541b61cd7b0a14f70242e2207fdb3f600c4d5 (diff)
downloaddjango-2f19306a125a9253d99b35b276d932e8e24d4e6f.tar.gz
Refs #27030 -- Added index type introspection on PostgreSQL.
Diffstat (limited to 'django/db/backends/postgresql/introspection.py')
-rw-r--r--django/db/backends/postgresql/introspection.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py
index 85ea66f6d1..50c8fb11f0 100644
--- a/django/db/backends/postgresql/introspection.py
+++ b/django/db/backends/postgresql/introspection.py
@@ -36,13 +36,15 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
ignored_tables = []
_get_indexes_query = """
- SELECT attr.attname, idx.indkey, idx.indisunique, idx.indisprimary
+ SELECT attr.attname, idx.indkey, idx.indisunique, idx.indisprimary,
+ am.amname
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2,
- pg_catalog.pg_index idx, pg_catalog.pg_attribute attr
+ pg_catalog.pg_index idx, pg_catalog.pg_attribute attr, pg_catalog.pg_am am
WHERE c.oid = idx.indrelid
AND idx.indexrelid = c2.oid
AND attr.attrelid = c.oid
AND attr.attnum = idx.indkey[0]
+ AND c2.relam = am.oid
AND c.relname = %s"""
def get_field_type(self, data_type, description):
@@ -132,6 +134,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
# row[1] (idx.indkey) is stored in the DB as an array. It comes out as
# a string of space-separated integers. This designates the field
# indexes (1-based) of the fields that have indexes on the table.
+ # row[4] is the type of index, e.g. btree, hash, etc.
# Here, we skip any indexes across multiple fields.
if ' ' in row[1]:
continue
@@ -142,6 +145,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
indexes[row[0]]['primary_key'] = True
if row[2]:
indexes[row[0]]['unique'] = True
+ indexes[row[0]]['type'] = row[4]
return indexes
def get_constraints(self, cursor, table_name):