diff options
author | Akshesh <aksheshdoshi@gmail.com> | 2016-08-25 12:42:17 +0530 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-08-30 08:48:55 -0400 |
commit | 4c7bf83cde9f698cad019a9b808dbe45a832d9c3 (patch) | |
tree | a74267c7e029b75f0b30132e706892654f45d34d /django/db/backends/postgresql/introspection.py | |
parent | 3fe92f44770890eced6bfac75342e04106d0d536 (diff) | |
download | django-4c7bf83cde9f698cad019a9b808dbe45a832d9c3.tar.gz |
Refs #27097, #27098 -- Moved PostgreSQL index type introspection to get_constraints().
Diffstat (limited to 'django/db/backends/postgresql/introspection.py')
-rw-r--r-- | django/db/backends/postgresql/introspection.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py index 50c8fb11f0..884270e534 100644 --- a/django/db/backends/postgresql/introspection.py +++ b/django/db/backends/postgresql/introspection.py @@ -36,15 +36,13 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): ignored_tables = [] _get_indexes_query = """ - SELECT attr.attname, idx.indkey, idx.indisunique, idx.indisprimary, - am.amname + SELECT attr.attname, idx.indkey, idx.indisunique, idx.indisprimary FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, - pg_catalog.pg_index idx, pg_catalog.pg_attribute attr, pg_catalog.pg_am am + pg_catalog.pg_index idx, pg_catalog.pg_attribute attr 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): @@ -134,7 +132,6 @@ 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 @@ -145,7 +142,6 @@ 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): @@ -216,10 +212,10 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): cursor.execute(""" SELECT indexname, array_agg(attname), indisunique, indisprimary, - array_agg(ordering) + array_agg(ordering), amname FROM ( SELECT - c2.relname as indexname, idx.*, attr.attname, + c2.relname as indexname, idx.*, attr.attname, am.amname, CASE WHEN am.amcanorder THEN CASE (option & 1) @@ -238,9 +234,9 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): AND c2.relam=am.oid AND c.relname = %s ) s2 - GROUP BY indexname, indisunique, indisprimary; + GROUP BY indexname, indisunique, indisprimary, amname;; """, [table_name]) - for index, columns, unique, primary, orders in cursor.fetchall(): + for index, columns, unique, primary, orders, type_ in cursor.fetchall(): if index not in constraints: constraints[index] = { "columns": columns, @@ -250,5 +246,6 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): "foreign_key": None, "check": False, "index": True, + "type": type_, } return constraints |