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

Open Beginner friendly
#3,295 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Quiet
Tech stack
rust, sql
Domain
documentation

Research direction

Start by reading the function registration in src/query/functions/src/scalars/decimal/src/cast.rs, then compare try-cast.md with the existing conversion-function pages under /docs/en/sql-reference/20-sql-functions/02-conversion-functions/. Add try-to-decimal.md with the documented TRY_TO_DECIMAL behavior and TRY_TO_NUMERIC and TRY_TO_NUMBER aliases; done means the page covers NULL-on-error conversion and precision/scale arguments.

Written by the indexing model from the issue text.

Description

documentation

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.

Dominant language
TypeScript
Stars
17
Forks
44
Avg merge
2d 7m
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from databendlabs/databend-docs

All issues in databendlabs/databend-docs

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.