summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-01-12 21:46:08 +0100
committerClaude Paroz <claude@2xlibre.net>2013-01-12 21:46:08 +0100
commit0171ba65dbbff377282c03b86c83036168c84b22 (patch)
tree2e90a191856bc9aa02805eaf427474628b76afe7 /django
parent223fc8eaf9d04eb2c277a30f4f46745d4403b69b (diff)
Fixed #17574 -- Implemented missing get_key_columns in PostgreSQL backend
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/postgresql_psycopg2/introspection.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/django/db/backends/postgresql_psycopg2/introspection.py b/django/db/backends/postgresql_psycopg2/introspection.py
index 440fa44c4e..a71d107357 100644
--- a/django/db/backends/postgresql_psycopg2/introspection.py
+++ b/django/db/backends/postgresql_psycopg2/introspection.py
@@ -66,6 +66,23 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
relations[row[0][0] - 1] = (row[1][0] - 1, row[2])
return relations
+ def get_key_columns(self, cursor, table_name):
+ key_columns = []
+ cursor.execute("""
+ SELECT kcu.column_name, ccu.table_name AS referenced_table, ccu.column_name AS referenced_column
+ FROM information_schema.constraint_column_usage ccu
+ LEFT JOIN information_schema.key_column_usage kcu
+ ON ccu.constraint_catalog = kcu.constraint_catalog
+ AND ccu.constraint_schema = kcu.constraint_schema
+ AND ccu.constraint_name = kcu.constraint_name
+ LEFT JOIN information_schema.table_constraints tc
+ ON ccu.constraint_catalog = tc.constraint_catalog
+ AND ccu.constraint_schema = tc.constraint_schema
+ AND ccu.constraint_name = tc.constraint_name
+ WHERE kcu.table_name = %s AND tc.constraint_type = 'FOREIGN KEY'""" , [table_name])
+ key_columns.extend(cursor.fetchall())
+ return key_columns
+
def get_indexes(self, cursor, table_name):
# This query retrieves each index on the given table, including the
# first associated field name