All the above could be replaced with a more compact/comprehensive code:
<pre>
    for row in c.execute(sql):
        # db only filter can be applied to sphinx config, no need to query postgres db
        # database filter
        db = None
        indices = row['sphinx_index']
        if options.index_filter is None:
            if options.database_filter is None or options.database_filter == row['database']:
                db = row['database']
            elif options.database_filter.split(".")[0] == row['database']:
                dbs =  pg_get_tables(row['sql'], row['database'])
                db = row['database'] if options.database_filter in dbs else None

        if options.command == 'list' and db is not None:
            for indice in indices.split(' '):
                resultat.append("%s -> %s" % (indice, db))

        if options.command == 'update':
            if indices.startswith(options.index_filter):
                resultat.append("%s" % (row['sphinx_index']))
</pre>