psycopg2 doesn't know how to quote identifier names, so we ask the server

def quote_names(db, names):
    """psycopg2 doesn't know how to quote identifier names, so we ask the server"""
    c = db.cursor()
    c.execute("SELECT pg_catalog.quote_ident(n) FROM pg_catalog.unnest(%s::text[]) n", [list(names)])
    return [name for (name,) in c]