Project

General

Profile

« Previous | Next » 

Revision 3318

sql.py: index_cols(): Fixed bug where index was looked up only by name, not by schema-qualified name, causing columns from other schemas (such as previous versions of public) to be included in the index columns list. This problem is only noticeable when a column in an index is deleted, as locationevent.datasource_id in locationevent_unique_accessioncode was recently.

View differences:

lib/sql.py
1031 1031
    constraint or a UNIQUE index, use this function.'''
1032 1032
    module = util.root_module(db.db)
1033 1033
    if module == 'psycopg2':
1034
        qual_index = sql_gen.as_Table(index).to_str(db)
1035
        qual_index_code = sql_gen.as_Value(qual_index).to_str(db)
1034 1036
        return list(values(run_query(db, '''\
1035 1037
SELECT attname
1036 1038
FROM
1037 1039
(
1038 1040
        SELECT attnum, attname
1039 1041
        FROM pg_index
1040
        JOIN pg_class index ON index.oid = indexrelid
1041
        JOIN pg_class table_ ON table_.oid = indrelid
1042 1042
        JOIN pg_attribute ON attrelid = indrelid AND attnum = ANY (indkey)
1043
        WHERE
1044
            table_.relname = '''+db.esc_value(table)+'''
1045
            AND index.relname = '''+db.esc_value(index)+'''
1043
        WHERE indexrelid = '''+qual_index_code+'''::regclass
1046 1044
    UNION
1047 1045
        SELECT attnum, attname
1048 1046
        FROM
......
1052 1050
                , (regexp_matches(indexprs, E':varattno (\\\\d+)', 'g'))[1]::int
1053 1051
                    AS indkey
1054 1052
            FROM pg_index
1055
            JOIN pg_class index ON index.oid = indexrelid
1056
            JOIN pg_class table_ ON table_.oid = indrelid
1057
            WHERE
1058
                table_.relname = '''+db.esc_value(table)+'''
1059
                AND index.relname = '''+db.esc_value(index)+'''
1053
            WHERE indexrelid = '''+qual_index_code+'''::regclass
1060 1054
        ) s
1061 1055
        JOIN pg_attribute ON attrelid = indrelid AND attnum = indkey
1062 1056
) s

Also available in: Unified diff