def METHOD_NAME(codelist, column):
    assert codelist.has_categories
    by_category = {}
    for code, category in codelist:
        by_category.setdefault(category, []).append(code)
    clauses = "\n".join(
        [
            f"WHEN {column} IN ({codelist_to_sql(codes)}) THEN {quote(category)}"
            for category, codes in by_category.items()
        ]
    )
    return f"""
    CASE
    {clauses}
    END
    """