From 709a8b861de14204f0e13c9a0fbfd61c11b3565d Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 18 Jan 2019 16:50:06 +0100 Subject: [PATCH] Optimized Oracle PKs introspection by adding get_primary_key_column(). --- django/db/backends/oracle/introspection.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/django/db/backends/oracle/introspection.py b/django/db/backends/oracle/introspection.py index 29193f0507..1fcba05510 100644 --- a/django/db/backends/oracle/introspection.py +++ b/django/db/backends/oracle/introspection.py @@ -173,6 +173,22 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): for row in cursor.fetchall() ] + def get_primary_key_column(self, cursor, table_name): + cursor.execute(""" + SELECT + cols.column_name + FROM + user_constraints, + user_cons_columns cols + WHERE + user_constraints.constraint_name = cols.constraint_name AND + user_constraints.constraint_type = 'P' AND + user_constraints.table_name = UPPER(%s) AND + cols.position = 1 + """, [table_name]) + row = cursor.fetchone() + return self.identifier_converter(row[0]) if row else None + def get_constraints(self, cursor, table_name): """ Retrieve any constraints or keys (unique, pk, fk, check, index) across