summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/introspection.py
diff options
context:
space:
mode:
authorTim Schneider <tim.schneider@nb-dev.de>2017-05-12 18:01:30 +0200
committerTim Graham <timograham@gmail.com>2017-05-15 08:33:31 -0400
commit3a5299c19cd5a38f7fa0f45ed2df7b10f0c9cf5d (patch)
tree39af17fe4a9ef72f886cc1bcc44aac7be59afb42 /django/db/backends/postgresql/introspection.py
parent3008f30f194af386c354416be4c483f0f6b15f33 (diff)
downloaddjango-3a5299c19cd5a38f7fa0f45ed2df7b10f0c9cf5d.tar.gz
Fixed #28197 -- Fixed introspection of index field ordering on PostgreSQL.
Diffstat (limited to 'django/db/backends/postgresql/introspection.py')
-rw-r--r--django/db/backends/postgresql/introspection.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py
index 0ec3bf7680..5be80f3edd 100644
--- a/django/db/backends/postgresql/introspection.py
+++ b/django/db/backends/postgresql/introspection.py
@@ -191,13 +191,17 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
"options": options,
}
# Now get indexes
+ # The row_number() function for ordering the index fields can be
+ # replaced by WITH ORDINALITY in the unnest() functions when support
+ # for PostgreSQL 9.3 is dropped.
cursor.execute("""
SELECT
- indexname, array_agg(attname), indisunique, indisprimary,
- array_agg(ordering), amname, exprdef, s2.attoptions
+ indexname, array_agg(attname ORDER BY rnum), indisunique, indisprimary,
+ array_agg(ordering ORDER BY rnum), amname, exprdef, s2.attoptions
FROM (
SELECT
- c2.relname as indexname, idx.*, attr.attname, am.amname,
+ row_number() OVER () as rnum, c2.relname as indexname,
+ idx.*, attr.attname, am.amname,
CASE
WHEN idx.indexprs IS NOT NULL THEN
pg_get_indexdef(idx.indexrelid)