// DuckDB built-in function names (scalar, aggregate, table, macro), used to
// reject workspace macros that would silently shadow a built-in (DuckDB
// allows the shadowing without error — verified on 1.5.4). Only
// identifier-shaped names are listed: workspace macro names are validated
// to `[a-z_][a-z0-9_]*` before this check, so operator names can't collide.
//
// Regenerate on DuckDB upgrades (sort in codepoint order — binary search):
//   python3 -c "import duckdb,re; print('\\n'.join(sorted(set(r[0] for r in
//     duckdb.connect().execute(\"SELECT DISTINCT lower(function_name) FROM
//     duckdb_functions()\").fetchall() if re.fullmatch(r'[a-z_][a-z0-9_]*', r[0])))))"

pub fn is_duckdb_builtin(name: &str) -> bool {
    DUCKDB_BUILTIN_FUNCTIONS
        .binary_search(&name.to_ascii_lowercase().as_str())
        .is_ok()
}

const DUCKDB_BUILTIN_FUNCTIONS: &[&str] = &[
    "__internal_compress_integral_ubigint",
    "__internal_compress_integral_uinteger",
    "__internal_compress_integral_usmallint",
    "__internal_compress_integral_utinyint",
    "__internal_compress_string_hugeint",
    "__internal_compress_string_ubigint",
    "__internal_compress_string_uhugeint",
    "__internal_compress_string_uinteger",
    "__internal_compress_string_usmallint",
    "__internal_compress_string_utinyint",
    "__internal_decompress_integral_bigint",
    "__internal_decompress_integral_hugeint",
    "__internal_decompress_integral_integer",
    "__internal_decompress_integral_smallint",
    "__internal_decompress_integral_ubigint",
    "__internal_decompress_integral_uhugeint",
    "__internal_decompress_integral_uinteger",
    "__internal_decompress_integral_usmallint",
    "__internal_decompress_string",
    "abs",
    "acos",
    "acosh",
    "add",
    "add_parquet_key",
    "age",
    "aggregate",
    "ago",
    "alias",
    "all_profiling_output",
    "any_value",
    "apply",
    "approx_count_distinct",
    "approx_quantile",
    "approx_top_k",
    "arbitrary",
    "arg_max",
    "arg_max_null",
    "arg_max_nulls_last",
    "arg_min",
    "arg_min_null",
    "arg_min_nulls_last",
    "argmax",
    "argmin",
    "array_agg",
    "array_aggr",
    "array_aggregate",
    "array_append",
    "array_apply",
    "array_cat",
    "array_concat",
    "array_contains",
    "array_cosine_distance",
    "array_cosine_similarity",
    "array_cross_product",
    "array_distance",
    "array_distinct",
    "array_dot_product",
    "array_extract",
    "array_filter",
    "array_grade_up",
    "array_has",
    "array_has_all",
    "array_has_any",
    "array_indexof",
    "array_inner_product",
    "array_intersect",
    "array_length",
    "array_negative_dot_product",
    "array_negative_inner_product",
    "array_pop_back",
    "array_pop_front",
    "array_position",
    "array_prepend",
    "array_push_back",
    "array_push_front",
    "array_reduce",
    "array_resize",
    "array_reverse",
    "array_reverse_sort",
    "array_select",
    "array_slice",
    "array_sort",
    "array_to_json",
    "array_to_string",
    "array_to_string_comma_default",
    "array_transform",
    "array_unique",
    "array_value",
    "array_where",
    "array_zip",
    "arrow_scan",
    "arrow_scan_dumb",
    "ascii",
    "asin",
    "asinh",
    "atan",
    "atan2",
    "atanh",
    "avg",
    "bar",
    "base64",
    "bin",
    "bit_and",
    "bit_count",
    "bit_length",
    "bit_or",
    "bit_position",
    "bit_xor",
    "bitstring",
    "bitstring_agg",
    "bool_and",
    "bool_or",
    "can_cast_implicitly",
    "cardinality",
    "cast_to_type",
    "cbrt",
    "ceil",
    "ceiling",
    "century",
    "char_length",
    "character_length",
    "checkpoint",
    "chr",
    "col_description",
    "collations",
    "combine",
    "concat",
    "concat_ws",
    "constant_or_null",
    "contains",
    "copy_database",
    "corr",
    "cos",
    "cosh",
    "cot",
    "count",
    "count_if",
    "count_star",
    "countif",
    "covar_pop",
    "covar_samp",
    "create_sort_key",
    "cume_dist",
    "current_catalog",
    "current_connection_id",
    "current_database",
    "current_date",
    "current_localtime",
    "current_localtimestamp",
    "current_query",
    "current_query_id",
    "current_role",
    "current_schema",
    "current_schemas",
    "current_setting",
    "current_transaction_id",
    "current_user",
    "currval",
    "damerau_levenshtein",
    "database_list",
    "database_size",
    "date_add",
    "date_diff",
    "date_part",
    "date_sub",
    "date_trunc",
    "datediff",
    "datepart",
    "datesub",
    "datetrunc",
    "day",
    "dayname",
    "dayofmonth",
    "dayofweek",
    "dayofyear",
    "days_in_month",
    "decade",
    "decode",
    "degrees",
    "dense_rank",
    "disable_checkpoint_on_shutdown",
    "disable_logging",
    "disable_object_cache",
    "disable_optimizer",
    "disable_print_progress_bar",
    "disable_profile",
    "disable_profiling",
    "disable_progress_bar",
    "disable_verification",
    "disable_verify_external",
    "disable_verify_fetch_row",
    "disable_verify_parallelism",
    "disable_verify_serializer",
    "divide",
    "duckdb_approx_database_count",
    "duckdb_columns",
    "duckdb_connection_count",
    "duckdb_constraints",
    "duckdb_coordinate_systems",
    "duckdb_databases",
    "duckdb_dependencies",
    "duckdb_extensions",
    "duckdb_external_file_cache",
    "duckdb_functions",
    "duckdb_indexes",
    "duckdb_keywords",
    "duckdb_log_contexts",
    "duckdb_logs",
    "duckdb_logs_parsed",
    "duckdb_memory",
    "duckdb_optimizers",
    "duckdb_prepared_statements",
    "duckdb_profiling_settings",
    "duckdb_schemas",
    "duckdb_secret_types",
    "duckdb_secrets",
    "duckdb_sequences",
    "duckdb_settings",
    "duckdb_table_sample",
    "duckdb_tables",
    "duckdb_temporary_files",
    "duckdb_types",
    "duckdb_variables",
    "duckdb_views",
    "editdist3",
    "element_at",
    "enable_checkpoint_on_shutdown",
    "enable_logging",
    "enable_object_cache",
    "enable_optimizer",
    "enable_print_progress_bar",
    "enable_profile",
    "enable_profiling",
    "enable_progress_bar",
    "enable_verification",
    "encode",
    "ends_with",
    "entropy",
    "enum_code",
    "enum_first",
    "enum_last",
    "enum_range",
    "enum_range_boundary",
    "epoch",
    "epoch_ms",
    "epoch_ns",
    "epoch_us",
    "equi_width_bins",
    "era",
    "error",
    "even",
    "exp",
    "extension_versions",
    "factorial",
    "favg",
    "fdiv",
    "fill",
    "filter",
    "finalize",
    "first",
    "first_value",
    "flatten",
    "floor",
    "fmod",
    "force_checkpoint",
    "format",
    "format_bytes",
    "format_pg_type",
    "format_type",
    "formatreadabledecimalsize",
    "formatreadablesize",
    "from_base64",
    "from_binary",
    "from_hex",
    "from_json",
    "from_json_strict",
    "fsum",
    "functions",
    "gamma",
    "gcd",
    "gen_random_uuid",
    "generate_series",
    "generate_subscripts",
    "geomean",
    "geometric_mean",
    "get_bit",
    "get_block_size",
    "get_current_time",
    "get_current_timestamp",
    "get_type",
    "getvariable",
    "glob",
    "grade_up",
    "greatest",
    "greatest_common_divisor",
    "group_concat",
    "hamming",
    "has_any_column_privilege",
    "has_column_privilege",
    "has_database_privilege",
    "has_foreign_data_wrapper_privilege",
    "has_function_privilege",
    "has_language_privilege",
    "has_schema_privilege",
    "has_sequence_privilege",
    "has_server_privilege",
    "has_table_privilege",
    "has_tablespace_privilege",
    "hash",
    "hex",
    "histogram",
    "histogram_exact",
    "histogram_values",
    "hour",
    "icu_calendar_names",
    "icu_collate_af",
    "icu_collate_am",
    "icu_collate_ar",
    "icu_collate_ar_sa",
    "icu_collate_as",
    "icu_collate_az",
    "icu_collate_be",
    "icu_collate_bg",
    "icu_collate_bn",
    "icu_collate_bo",
    "icu_collate_br",
    "icu_collate_bs",
    "icu_collate_ca",
    "icu_collate_ceb",
    "icu_collate_chr",
    "icu_collate_cs",
    "icu_collate_cy",
    "icu_collate_da",
    "icu_collate_de",
    "icu_collate_de_at",
    "icu_collate_dsb",
    "icu_collate_dz",
    "icu_collate_ee",
    "icu_collate_el",
    "icu_collate_en",
    "icu_collate_en_us",
    "icu_collate_eo",
    "icu_collate_es",
    "icu_collate_et",
    "icu_collate_fa",
    "icu_collate_fa_af",
    "icu_collate_ff",
    "icu_collate_fi",
    "icu_collate_fil",
    "icu_collate_fo",
    "icu_collate_fr",
    "icu_collate_fr_ca",
    "icu_collate_fy",
    "icu_collate_ga",
    "icu_collate_gl",
    "icu_collate_gu",
    "icu_collate_ha",
    "icu_collate_haw",
    "icu_collate_he",
    "icu_collate_he_il",
    "icu_collate_hi",
    "icu_collate_hr",
    "icu_collate_hsb",
    "icu_collate_hu",
    "icu_collate_hy",
    "icu_collate_id",
    "icu_collate_id_id",
    "icu_collate_ig",
    "icu_collate_is",
    "icu_collate_it",
    "icu_collate_ja",
    "icu_collate_ka",
    "icu_collate_kk",
    "icu_collate_kl",
    "icu_collate_km",
    "icu_collate_kn",
    "icu_collate_ko",
    "icu_collate_kok",
    "icu_collate_ku",
    "icu_collate_ky",
    "icu_collate_lb",
    "icu_collate_lij",
    "icu_collate_lkt",
    "icu_collate_ln",
    "icu_collate_lo",
    "icu_collate_lt",
    "icu_collate_lv",
    "icu_collate_mk",
    "icu_collate_ml",
    "icu_collate_mn",
    "icu_collate_mr",
    "icu_collate_ms",
    "icu_collate_mt",
    "icu_collate_my",
    "icu_collate_nb",
    "icu_collate_nb_no",
    "icu_collate_ne",
    "icu_collate_nl",
    "icu_collate_nn",
    "icu_collate_noaccent",
    "icu_collate_nso",
    "icu_collate_om",
    "icu_collate_or",
    "icu_collate_pa",
    "icu_collate_pa_in",
    "icu_collate_pl",
    "icu_collate_ps",
    "icu_collate_pt",
    "icu_collate_ro",
    "icu_collate_ru",
    "icu_collate_sa",
    "icu_collate_se",
    "icu_collate_si",
    "icu_collate_sk",
    "icu_collate_sl",
    "icu_collate_smn",
    "icu_collate_sq",
    "icu_collate_sr",
    "icu_collate_sr_ba",
    "icu_collate_sr_me",
    "icu_collate_sr_rs",
    "icu_collate_st",
    "icu_collate_sv",
    "icu_collate_sw",
    "icu_collate_ta",
    "icu_collate_te",
    "icu_collate_th",
    "icu_collate_tk",
    "icu_collate_tn",
    "icu_collate_to",
    "icu_collate_tr",
    "icu_collate_ug",
    "icu_collate_uk",
    "icu_collate_ur",
    "icu_collate_uz",
    "icu_collate_vi",
    "icu_collate_wae",
    "icu_collate_wo",
    "icu_collate_xh",
    "icu_collate_yi",
    "icu_collate_yo",
    "icu_collate_yue",
    "icu_collate_yue_cn",
    "icu_collate_zh",
    "icu_collate_zh_cn",
    "icu_collate_zh_hk",
    "icu_collate_zh_mo",
    "icu_collate_zh_sg",
    "icu_collate_zh_tw",
    "icu_collate_zu",
    "icu_sort_key",
    "ilike_escape",
    "import_database",
    "in_search_path",
    "inet_client_addr",
    "inet_client_port",
    "inet_server_addr",
    "inet_server_port",
    "instr",
    "is_histogram_other_bin",
    "isfinite",
    "isinf",
    "isnan",
    "isodow",
    "isoyear",
    "jaccard",
    "jaro_similarity",
    "jaro_winkler_similarity",
    "json",
    "json_array",
    "json_array_length",
    "json_contains",
    "json_deserialize_sql",
    "json_each",
    "json_execute_serialized_sql",
    "json_exists",
    "json_extract",
    "json_extract_path",
    "json_extract_path_text",
    "json_extract_string",
    "json_group_array",
    "json_group_object",
    "json_group_structure",
    "json_keys",
    "json_merge_patch",
    "json_object",
    "json_pretty",
    "json_quote",
    "json_serialize_plan",
    "json_serialize_sql",
    "json_structure",
    "json_transform",
    "json_transform_strict",
    "json_tree",
    "json_type",
    "json_valid",
    "json_value",
    "julian",
    "kahan_sum",
    "kurtosis",
    "kurtosis_pop",
    "lag",
    "last",
    "last_day",
    "last_value",
    "lcase",
    "lcm",
    "lead",
    "least",
    "least_common_multiple",
    "left",
    "left_grapheme",
    "len",
    "length",
    "length_grapheme",
    "levenshtein",
    "lgamma",
    "like_escape",
    "list",
    "list_aggr",
    "list_aggregate",
    "list_any_value",
    "list_append",
    "list_apply",
    "list_approx_count_distinct",
    "list_avg",
    "list_bit_and",
    "list_bit_or",
    "list_bit_xor",
    "list_bool_and",
    "list_bool_or",
    "list_cat",
    "list_concat",
    "list_contains",
    "list_cosine_distance",
    "list_cosine_similarity",
    "list_count",
    "list_distance",
    "list_distinct",
    "list_dot_product",
    "list_element",
    "list_entropy",
    "list_extract",
    "list_filter",
    "list_first",
    "list_grade_up",
    "list_has",
    "list_has_all",
    "list_has_any",
    "list_histogram",
    "list_indexof",
    "list_inner_product",
    "list_intersect",
    "list_kurtosis",
    "list_kurtosis_pop",
    "list_last",
    "list_mad",
    "list_max",
    "list_median",
    "list_min",
    "list_mode",
    "list_negative_dot_product",
    "list_negative_inner_product",
    "list_pack",
    "list_position",
    "list_prepend",
    "list_product",
    "list_reduce",
    "list_resize",
    "list_reverse",
    "list_reverse_sort",
    "list_select",
    "list_sem",
    "list_skewness",
    "list_slice",
    "list_sort",
    "list_stddev_pop",
    "list_stddev_samp",
    "list_string_agg",
    "list_sum",
    "list_transform",
    "list_unique",
    "list_value",
    "list_var_pop",
    "list_var_samp",
    "list_where",
    "list_zip",
    "listagg",
    "ln",
    "log",
    "log10",
    "log2",
    "lower",
    "lpad",
    "ltrim",
    "mad",
    "make_date",
    "make_time",
    "make_timestamp",
    "make_timestamp_ms",
    "make_timestamp_ns",
    "make_timestamptz",
    "make_type",
    "map",
    "map_concat",
    "map_contains",
    "map_contains_entry",
    "map_contains_value",
    "map_entries",
    "map_extract",
    "map_extract_value",
    "map_from_entries",
    "map_keys",
    "map_to_pg_oid",
    "map_values",
    "max",
    "max_by",
    "md5",
    "md5_number",
    "md5_number_lower",
    "md5_number_upper",
    "mean",
    "median",
    "metadata_info",
    "microsecond",
    "millennium",
    "millisecond",
    "min",
    "min_by",
    "minute",
    "mismatches",
    "mod",
    "mode",
    "month",
    "monthname",
    "multiply",
    "nanosecond",
    "nextafter",
    "nextval",
    "nfc_normalize",
    "normalized_interval",
    "not_ilike_escape",
    "not_like_escape",
    "now",
    "nth_value",
    "ntile",
    "nullif",
    "obj_description",
    "octet_length",
    "ord",
    "pandas_scan",
    "parquet_bloom_probe",
    "parquet_file_metadata",
    "parquet_full_metadata",
    "parquet_kv_metadata",
    "parquet_metadata",
    "parquet_scan",
    "parquet_schema",
    "parse_dirname",
    "parse_dirpath",
    "parse_duckdb_log_message",
    "parse_filename",
    "parse_formatted_bytes",
    "parse_path",
    "percent_rank",
    "pg_collation_is_visible",
    "pg_conf_load_time",
    "pg_conversion_is_visible",
    "pg_function_is_visible",
    "pg_get_constraintdef",
    "pg_get_expr",
    "pg_get_viewdef",
    "pg_has_role",
    "pg_is_other_temp_schema",
    "pg_my_temp_schema",
    "pg_opclass_is_visible",
    "pg_operator_is_visible",
    "pg_opfamily_is_visible",
    "pg_postmaster_start_time",
    "pg_size_pretty",
    "pg_sleep",
    "pg_table_is_visible",
    "pg_timezone_names",
    "pg_ts_config_is_visible",
    "pg_ts_dict_is_visible",
    "pg_ts_parser_is_visible",
    "pg_ts_template_is_visible",
    "pg_type_is_visible",
    "pg_typeof",
    "pi",
    "platform",
    "position",
    "pow",
    "power",
    "pragma_collations",
    "pragma_database_size",
    "pragma_metadata_info",
    "pragma_platform",
    "pragma_show",
    "pragma_storage_info",
    "pragma_table_info",
    "pragma_user_agent",
    "pragma_version",
    "prefix",
    "printf",
    "product",
    "python_map_function",
    "quantile",
    "quantile_cont",
    "quantile_disc",
    "quarter",
    "query",
    "query_table",
    "radians",
    "random",
    "range",
    "rank",
    "rank_dense",
    "read_blob",
    "read_csv",
    "read_csv_auto",
    "read_duckdb",
    "read_json",
    "read_json_auto",
    "read_json_objects",
    "read_json_objects_auto",
    "read_ndjson",
    "read_ndjson_auto",
    "read_ndjson_objects",
    "read_parquet",
    "read_text",
    "reduce",
    "regexp_escape",
    "regexp_extract",
    "regexp_extract_all",
    "regexp_full_match",
    "regexp_matches",
    "regexp_replace",
    "regexp_split_to_array",
    "regexp_split_to_table",
    "regr_avgx",
    "regr_avgy",
    "regr_count",
    "regr_intercept",
    "regr_r2",
    "regr_slope",
    "regr_sxx",
    "regr_sxy",
    "regr_syy",
    "remap_struct",
    "repeat",
    "repeat_row",
    "replace",
    "replace_type",
    "reservoir_quantile",
    "reverse",
    "right",
    "right_grapheme",
    "round",
    "round_even",
    "roundbankers",
    "row",
    "row_number",
    "row_to_json",
    "rpad",
    "rtrim",
    "second",
    "sem",
    "seq_scan",
    "session_user",
    "set_bit",
    "setseed",
    "sha1",
    "sha256",
    "shobj_description",
    "show",
    "show_databases",
    "show_tables",
    "show_tables_expanded",
    "sign",
    "signbit",
    "sin",
    "sinh",
    "skewness",
    "sleep_ms",
    "sniff_csv",
    "split",
    "split_part",
    "sqrt",
    "st_asbinary",
    "st_astext",
    "st_aswkb",
    "st_aswkt",
    "st_crs",
    "st_geomfromwkb",
    "st_intersects_extent",
    "st_setcrs",
    "starts_with",
    "stats",
    "stddev",
    "stddev_pop",
    "stddev_samp",
    "storage_info",
    "str_split",
    "str_split_regex",
    "strftime",
    "string_agg",
    "string_split",
    "string_split_regex",
    "string_to_array",
    "strip_accents",
    "strlen",
    "strpos",
    "strptime",
    "struct_concat",
    "struct_contains",
    "struct_extract",
    "struct_extract_at",
    "struct_has",
    "struct_indexof",
    "struct_insert",
    "struct_keys",
    "struct_pack",
    "struct_position",
    "struct_update",
    "struct_values",
    "substr",
    "substring",
    "substring_grapheme",
    "subtract",
    "suffix",
    "sum",
    "sum_no_overflow",
    "sumkahan",
    "summary",
    "switch",
    "table_info",
    "tan",
    "tanh",
    "test_all_types",
    "test_vector_types",
    "time_bucket",
    "timetz_byte_comparable",
    "timezone",
    "timezone_hour",
    "timezone_minute",
    "to_base",
    "to_base64",
    "to_binary",
    "to_centuries",
    "to_days",
    "to_decades",
    "to_hex",
    "to_hours",
    "to_json",
    "to_microseconds",
    "to_millennia",
    "to_milliseconds",
    "to_minutes",
    "to_months",
    "to_quarters",
    "to_seconds",
    "to_timestamp",
    "to_weeks",
    "to_years",
    "today",
    "transaction_timestamp",
    "translate",
    "trim",
    "trunc",
    "truncate_duckdb_logs",
    "try_strptime",
    "txid_current",
    "typeof",
    "ucase",
    "unbin",
    "unhex",
    "unicode",
    "union_extract",
    "union_tag",
    "union_value",
    "unnest",
    "unpivot_list",
    "upper",
    "url_decode",
    "url_encode",
    "user",
    "user_agent",
    "uuid",
    "uuid_extract_timestamp",
    "uuid_extract_version",
    "uuidv4",
    "uuidv7",
    "var_pop",
    "var_samp",
    "variance",
    "variant_bytes_to_variant",
    "variant_extract",
    "variant_normalize",
    "variant_to_parquet_variant",
    "variant_typeof",
    "vector_type",
    "verify_external",
    "verify_fetch_row",
    "verify_parallelism",
    "verify_serializer",
    "version",
    "wavg",
    "week",
    "weekday",
    "weekofyear",
    "weighted_avg",
    "which_secret",
    "write_log",
    "xor",
    "year",
    "yearweek",
];
