fix findindex in postgresql 10
This commit is contained in:
parent
894a609f3f
commit
302af9cda4
1 changed files with 10 additions and 6 deletions
|
@ -45,12 +45,16 @@ class Command(BaseCommand):
|
|||
indexes = connection.introspection.get_indexes(cursor, table)
|
||||
drop = []
|
||||
if column in indexes:
|
||||
sql = "SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \
|
||||
"WHERE indexdef LIKE '%ON {table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column)
|
||||
cursor.execute(sql)
|
||||
for r in cursor:
|
||||
if 'USING gin' not in r[1]:
|
||||
drop.append(r[0])
|
||||
for sql in (
|
||||
"SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \
|
||||
"WHERE indexdef LIKE '%ON {table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column),
|
||||
"SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \
|
||||
"WHERE indexdef LIKE '%ON public.{table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column),
|
||||
):
|
||||
cursor.execute(sql)
|
||||
for r in cursor:
|
||||
if 'USING gin' not in r[1]:
|
||||
drop.append(r[0])
|
||||
if drop:
|
||||
for idx in drop:
|
||||
sql = 'DROP INDEX ' + idx
|
||||
|
|
Loading…
Reference in a new issue