pub fn validate_function_name(name: &str) -> Result<(), ExtensionError>Expand description
Validates a DuckDB function name.
§Rules
- Must not be empty
- Must not exceed 256 characters
- Must start with an ASCII letter or underscore
- Must contain only ASCII letters, digits, or underscores
- Must not contain interior null bytes
- Must not be one of
DUCKDB_RESERVED_KEYWORDSorDUCKDB_UNCALLABLE_KEYWORDS(compared case-insensitively)
Every one of these is something that would actually break: a name needing
quotes in SQL (including a reserved keyword such as order), a name
starting with a digit that the parser reads as a number, or a name a C
string truncates. Casing is not checked — see the
module docs for why enforcing snake_case
here would make a name DuckDB accepts unregisterable.
§Errors
Returns ExtensionError describing the first rule violation found.
§Example
use quack_rs::validate::validate_function_name;
assert!(validate_function_name("word_count").is_ok());
assert!(validate_function_name("my_func_v2").is_ok());
assert!(validate_function_name("_internal").is_ok());
// DuckDB ships `formatReadableSize`; mixed case is legal.
assert!(validate_function_name("formatReadableSize").is_ok());
assert!(validate_function_name("").is_err()); // empty
assert!(validate_function_name("my-func").is_err()); // needs quoting in SQL
assert!(validate_function_name("1func").is_err()); // parsed as a number
assert!(validate_function_name("my func").is_err()); // needs quoting in SQL
assert!(validate_function_name("order").is_err()); // reserved keyword
assert!(validate_function_name("coalesce").is_err()); // the COALESCE operator takes the call
assert!(validate_function_name("left").is_ok()); // keyword, but callable