diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2017-09-13 20:12:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-13 20:12:32 +0200 |
commit | c6a1faecc3d6e25597a7105df74f11678f2f2aac (patch) | |
tree | 84f7d7ce04ec478ba9652ecdf3728a259538864a /django/db/backends/postgresql/introspection.py | |
parent | c2ecef869ce46349e79c39610cd66a576d78289e (diff) | |
download | django-c6a1faecc3d6e25597a7105df74f11678f2f2aac.tar.gz |
Refs #27090 -- Added real database sequence introspection.
Thanks Mariusz Felisiak for the Oracle part and Tim Graham for the
review.
Diffstat (limited to 'django/db/backends/postgresql/introspection.py')
-rw-r--r-- | django/db/backends/postgresql/introspection.py | 20 |
1 files changed, 20 insertions, 0 deletions
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)} |