Ticket #2061: pgsql_introspection_droppedcolumns.diff

File pgsql_introspection_droppedcolumns.diff, 2.0 KB (added by Chris Chamberlin <dja@…>, 18 years ago)

patch of django/db/backends/postgresql/introspection.py

  • django/db/backends/postgresql/introspection.py

     
    4545        {'primary_key': boolean representing whether it's the primary key,
    4646         'unique': boolean representing whether it's a unique index}
    4747    """
    48     # Get the table description because we only have the column indexes, and we
    49     # need the column names.
    50     desc = get_table_description(cursor, table_name)
    51     # This query retrieves each index on the given table.
     48    # This query retrieves each index on the given table, including the
     49    # first associated field name
    5250    cursor.execute("""
    53         SELECT idx.indkey, idx.indisunique, idx.indisprimary
     51        SELECT attr.attname, idx.indkey, idx.indisunique, idx.indisprimary
    5452        FROM pg_catalog.pg_class c, pg_catalog.pg_class c2,
    55             pg_catalog.pg_index idx
     53            pg_catalog.pg_index idx, pg_catalog.pg_attribute attr
    5654        WHERE c.oid = idx.indrelid
    5755            AND idx.indexrelid = c2.oid
     56            AND attr.attrelid = c.oid
     57            AND attr.attnum = idx.indkey[0]
    5858            AND c.relname = %s""", [table_name])
    5959    indexes = {}
    6060    for row in cursor.fetchall():
    61         # row[0] (idx.indkey) is stored in the DB as an array. It comes out as
     61        # row[1] (idx.indkey) is stored in the DB as an array. It comes out as
    6262        # a string of space-separated integers. This designates the field
    6363        # indexes (1-based) of the fields that have indexes on the table.
    6464        # Here, we skip any indexes across multiple fields.
    65         if ' ' in row[0]:
     65        if ' ' in row[1]:
    6666            continue
    67         col_name = desc[int(row[0])-1][0]
    68         indexes[col_name] = {'primary_key': row[2], 'unique': row[1]}
     67        indexes[row[0]] = {'primary_key': row[3], 'unique': row[2]}
    6968    return indexes
    7069
    7170# Maps type codes to Django Field types.
Back to Top