#!/usr/bin/python import itertools columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; indexes = [] for cols in itertools.permutations(columns): indexes.append(cols) for l in range(1,len(cols)): indexes.append(cols[:l]) indexes = set(indexes) for idx in indexes: if len(idx) < 4: print 'create index on t (' , (','.join(idx)) , ');'