IGNORE = set(['CREATE FUNCTION'])

def _filter(stmt, allow=0):
    ddl = [t for t in stmt.tokens if t.ttype in (tokens.DDL, tokens.Keyword)]
start = ' '.join(d.value for d in ddl[:2])
if ddl and start in IGNORE:
    allow = 1
for tok in stmt.tokens:
    if allow or not isinstance(tok, sqlparse.sql.Comment):
        yield tok
for stmt in sqlparse.split(queries):
    sql = sqlparse.parse(stmt)[0]
print(sqlparse.sql.TokenList([t for t in _filter(sql)]))
Howto clean comments from raw sql file