Revision 5520
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
1111 | 1111 |
else: raise NotImplementedError("Can't get constraint condition for " |
1112 | 1112 |
+module+' database') |
1113 | 1113 |
|
1114 |
def index_cols(db, index): |
|
1115 |
'''Can also use this for UNIQUE constraints, because a UNIQUE index is |
|
1116 |
automatically created. When you don't know whether something is a UNIQUE |
|
1117 |
constraint or a UNIQUE index, use this function.''' |
|
1114 |
def index_exprs(db, index): |
|
1118 | 1115 |
index = sql_gen.as_Table(index) |
1119 | 1116 |
module = util.root_module(db.db) |
1120 | 1117 |
if module == 'psycopg2': |
1121 | 1118 |
qual_index = sql_gen.Literal(index.to_str(db)) |
1122 |
return map(sql_gen.parse_expr_col, values(run_query(db, '''\
|
|
1119 |
return list(values(run_query(db, '''\
|
|
1123 | 1120 |
SELECT pg_get_indexdef(indexrelid, generate_series(1, indnatts), true) |
1124 | 1121 |
FROM pg_index |
1125 | 1122 |
WHERE indexrelid = '''+qual_index.to_str(db)+'''::regclass |
1126 | 1123 |
''' |
1127 | 1124 |
, cacheable=True, log_level=4))) |
1128 |
else: raise NotImplementedError("Can't list index columns for "+module+ |
|
1129 |
' database') |
|
1125 |
else: raise NotImplementedError() |
|
1130 | 1126 |
|
1127 |
def index_cols(db, index): |
|
1128 |
'''Can also use this for UNIQUE constraints, because a UNIQUE index is |
|
1129 |
automatically created. When you don't know whether something is a UNIQUE |
|
1130 |
constraint or a UNIQUE index, use this function.''' |
|
1131 |
return map(sql_gen.parse_expr_col, index_exprs(db, index)) |
|
1132 |
|
|
1131 | 1133 |
def index_cond(db, index): |
1132 | 1134 |
index = sql_gen.as_Table(index) |
1133 | 1135 |
module = util.root_module(db.db) |
Also available in: Unified diff
sql.py: Added index_exprs() and use it in index_cols()