Skip to content

docs: missing documentation for TRY_TO_DECIMAL, TRY_TO_NUMERIC, and TRY_TO_NUMBER conversion functions #3295

@sundy-li

Description

@sundy-li

What's Missing

Three conversion function aliases registered in the Databend function registry have no documentation:

  • TRY_TO_DECIMAL(expr[, precision, scale]) — converts a value to DECIMAL, returning NULL on error instead of throwing
  • TRY_TO_NUMERIC — alias for TRY_TO_DECIMAL
  • TRY_TO_NUMBER — alias for TRY_TO_DECIMAL

The non-try counterparts TO_DECIMAL / TO_NUMERIC / TO_NUMBER are also undocumented, but the TRY_ variants are especially important for safe data ingestion pipelines.

Source File

/workspace/databend/src/query/functions/src/scalars/decimal/src/cast.rs

Relevant registrations:

registry.register_function_factory(
    "try_to_decimal",
    FunctionFactory::Closure(Box::new(move |params, args_type| {
        let mut f = factory(params, args_type)?;
        f.signature.name = "try_to_decimal".to_string();
        Some(Arc::new(f.error_to_null()))
    })),
);
registry.register_aliases("try_to_decimal", &["try_to_numeric", "try_to_number"]);

What They Do

TRY_TO_DECIMAL(expr[, precision[, scale]]) attempts to cast any numeric or string expression to a DECIMAL(precision, scale) value. Unlike TO_DECIMAL, it returns NULL rather than raising an error when the conversion fails (e.g., the input string is not a valid number, or the value overflows the target precision/scale).

TRY_TO_NUMERIC and TRY_TO_NUMBER are exact aliases.

Suggested Doc Location

/docs/en/sql-reference/20-sql-functions/02-conversion-functions/

A new page try-to-decimal.md (with title_includes: TRY_TO_NUMERIC, TRY_TO_NUMBER) should be added, mirroring the pattern of try-cast.md and the existing to-decimal.md (if it exists) or alongside to-float32.md, to-int8.md, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions