Revision 853
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/sql.py | ||
---|---|---|
145 | 145 |
recover=recover), 0) |
146 | 146 |
return cache[table] |
147 | 147 |
|
148 |
def index_cols(db, table, index): |
|
149 |
'''Can also use this for UNIQUE constraints, because a UNIQUE index is |
|
150 |
automatically created. When you don't know whether something is a UNIQUE |
|
151 |
constraint or a UNIQUE index, use this function.''' |
|
152 |
check_name(table) |
|
153 |
check_name(index) |
|
154 |
module = util.root_module(db) |
|
155 |
if module == 'psycopg2': |
|
156 |
return list(values(run_query(db, '''\ |
|
157 |
SELECT attname |
|
158 |
FROM pg_index |
|
159 |
JOIN pg_class index ON index.oid = indexrelid |
|
160 |
JOIN pg_class table_ ON table_.oid = indrelid |
|
161 |
JOIN pg_attribute ON attrelid = indrelid AND attnum = ANY (indkey) |
|
162 |
WHERE |
|
163 |
table_.relname = %(table)s |
|
164 |
AND index.relname = %(index)s |
|
165 |
ORDER BY attnum |
|
166 |
''', |
|
167 |
{'table': table, 'index': index}))) |
|
168 |
else: raise NotImplementedError("Can't list index columns for "+module+ |
|
169 |
' database') |
|
170 |
|
|
148 | 171 |
def constraint_cols(db, table, constraint): |
149 | 172 |
check_name(table) |
150 | 173 |
check_name(constraint) |
Also available in: Unified diff
sql.py: Added index_cols() to get cols used by an index (similar to constraint_cols())