From 3a5299c19cd5a38f7fa0f45ed2df7b10f0c9cf5d Mon Sep 17 00:00:00 2001 From: Tim Schneider Date: Fri, 12 May 2017 18:01:30 +0200 Subject: Fixed #28197 -- Fixed introspection of index field ordering on PostgreSQL. --- django/db/backends/postgresql/introspection.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'django') 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) -- cgit v1.3