From b769bbd4f6a3cd1bcd9ebf3559ec6ea0f9b50565 Mon Sep 17 00:00:00 2001 From: Daniel Wiesmann Date: Fri, 19 Jun 2015 16:46:03 +0100 Subject: Fixed #23804 -- Added RasterField for PostGIS. Thanks to Tim Graham and Claude Paroz for the reviews and patches. --- .../db/backends/postgresql_psycopg2/introspection.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'django/db') diff --git a/django/db/backends/postgresql_psycopg2/introspection.py b/django/db/backends/postgresql_psycopg2/introspection.py index 32c69bc510..9b3e9074b2 100644 --- a/django/db/backends/postgresql_psycopg2/introspection.py +++ b/django/db/backends/postgresql_psycopg2/introspection.py @@ -34,6 +34,16 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): ignored_tables = [] + _get_indexes_query = """ + 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 + WHERE c.oid = idx.indrelid + AND idx.indexrelid = c2.oid + AND attr.attrelid = c.oid + AND attr.attnum = idx.indkey[0] + AND c.relname = %s""" + def get_field_type(self, data_type, description): field_type = super(DatabaseIntrospection, self).get_field_type(data_type, description) if field_type == 'IntegerField' and description.default and 'nextval' in description.default: @@ -108,15 +118,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): def get_indexes(self, cursor, table_name): # This query retrieves each index on the given table, including the # first associated field name - cursor.execute(""" - 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 - WHERE c.oid = idx.indrelid - AND idx.indexrelid = c2.oid - AND attr.attrelid = c.oid - AND attr.attnum = idx.indkey[0] - AND c.relname = %s""", [table_name]) + cursor.execute(self._get_indexes_query, [table_name]) indexes = {} for row in cursor.fetchall(): # row[1] (idx.indkey) is stored in the DB as an array. It comes out as -- cgit v1.3