Ticket #20888: 20888-draft.diff

File 20888-draft.diff, 1.7 KB (added by Tim Graham, 8 years ago)
  • django/db/backends/postgresql/introspection.py

    diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py
    index 24bd45c..9a1c28f 100644
    a b class DatabaseIntrospection(BaseDatabaseIntrospection):  
    207207                        WHEN idx.indexprs IS NOT NULL THEN
    208208                            pg_get_indexdef(idx.indexrelid)
    209209                    END AS exprdef,
    210                     CASE
    211                         WHEN am.amcanorder THEN
    212                             CASE (option & 1)
    213                                 WHEN 1 THEN 'DESC' ELSE 'ASC'
    214                             END
     210                    CASE am.amname WHEN 'btree' THEN
     211                        CASE i.indoption[(i.keys).n - 1] & 1
     212                            WHEN 1 THEN 'DESC' ELSE 'ASC'
     213                        END
     214                        ELSE NULL
    215215                    END as ordering
    216216                FROM (
    217217                    SELECT
    class DatabaseIntrospection(BaseDatabaseIntrospection):  
    222222                LEFT JOIN pg_class c2 ON idx.indexrelid = c2.oid
    223223                LEFT JOIN pg_am am ON c2.relam = am.oid
    224224                LEFT JOIN pg_attribute attr ON attr.attrelid = c.oid AND attr.attnum = idx.key
     225                LEFT JOIN (SELECT i.indexrelid, i.indrelid, i.indoption,
     226                     i.indisunique, i.indisclustered, i.indpred,
     227                     i.indexprs,
     228                     information_schema._pg_expandarray(i.indkey) AS keys
     229                   FROM pg_catalog.pg_index i) i ON (c2.oid = i.indrelid)
    225230                WHERE c.relname = %s
    226231            ) s2
    227232            GROUP BY indexname, indisunique, indisprimary, amname, exprdef;
Back to Top