Django

Code

Changeset 3047

Show
Ignore:
Timestamp:
06/01/06 11:27:41 (2 years ago)
Author:
adrian
Message:

Fixed #2061 -- Fixed PostgreSQL index introspection in tables that have dropped columns. Thanks, Chris Chamberlin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r2985 r3047  
    4646    Antonio Cavedoni <http://cavedoni.com/> 
    4747    C8E 
     48    Chris Chamberlin <dja@cdc.msbx.net> 
    4849    Amit Chakradeo <http://amit.chakradeo.net/> 
    4950    ChaosKCW 
  • django/trunk/django/db/backends/postgresql/introspection.py

    r2809 r3047  
    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 
  • django/trunk/django/db/backends/postgresql_psycopg2/introspection.py

    r2934 r3047  
    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