From c6a1faecc3d6e25597a7105df74f11678f2f2aac Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Wed, 13 Sep 2017 20:12:32 +0200 Subject: Refs #27090 -- Added real database sequence introspection. Thanks Mariusz Felisiak for the Oracle part and Tim Graham for the review. --- django/db/backends/postgresql/introspection.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'django/db/backends/postgresql/introspection.py') diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py index 5be80f3edd..1e987d1779 100644 --- a/django/db/backends/postgresql/introspection.py +++ b/django/db/backends/postgresql/introspection.py @@ -82,6 +82,26 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): for line in cursor.description ] + def get_sequences(self, cursor, table_name, table_fields=()): + sequences = [] + cursor.execute(""" + SELECT s.relname as sequence_name, col.attname + FROM pg_class s + JOIN pg_namespace sn ON sn.oid = s.relnamespace + JOIN pg_depend d ON d.refobjid = s.oid AND d.refclassid='pg_class'::regclass + JOIN pg_attrdef ad ON ad.oid = d.objid AND d.classid = 'pg_attrdef'::regclass + JOIN pg_attribute col ON col.attrelid = ad.adrelid AND col.attnum = ad.adnum + JOIN pg_class tbl ON tbl.oid = ad.adrelid + JOIN pg_namespace n ON n.oid = tbl.relnamespace + WHERE s.relkind = 'S' + AND d.deptype in ('a', 'n') + AND n.nspname = 'public' + AND tbl.relname = %s + """, [table_name]) + for row in cursor.fetchall(): + sequences.append({'name': row[0], 'table': table_name, 'column': row[1]}) + return sequences + def get_relations(self, cursor, table_name): """ Return a dictionary of {field_name: (field_name_other_table, other_table)} -- cgit v1.2.1