Skip to main content

validate_sql_identifier

Function validate_sql_identifier 

Source
pub fn validate_sql_identifier(
    value: &str,
    field: &str,
    path: &str,
) -> Result<(), ValidationError>
Expand description

Validates that value is a safe SQL identifier.

Accepts [A-Za-z_][A-Za-z0-9_]* with up to two schema dots (e.g. "v_user", "public.v_user", or "catalog.schema.table"). Rejects anything that could be SQL injection or cause a runtime syntax error.

Each dot-separated segment is limited to 63 bytes (PostgreSQL NAMEDATALEN - 1). Identifiers exceeding this limit are silently truncated by PostgreSQL, which can cause confusing “relation not found” errors at runtime.

§Arguments

  • value: The string to validate (e.g. "v_user" or "public.v_user")
  • field: The TOML/decorator field name ("sql_source", "function_name")
  • path: Human-readable location for the error ("Query.users", "Mutation.createPost")

§Errors

Returns a ValidationError if value is empty, exceeds the PostgreSQL identifier length limit, or does not match the safe identifier pattern.