Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Databases and Redis

Snowflake refuses TRY_CAST on a NUMBER or VARIANT column

Your error

001065 (22023): SQL compilation error:2 more lines it can show

Fix it fast

Most common cause, 1 of 2

The input column already has a typed value, such as NUMBER or DATE

If a bad value should fail loudly, use CAST or the :: operator on the typed column.

Fix
-- fail on bad values
SELECT amount::NUMBER(10,0) FROM orders;

-- NULL on bad values
SELECT TRY_CAST(amount::VARCHAR AS NUMBER(10,0)) FROM orders;
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Snowflake raises Function TRY_CAST cannot be used with arguments of types NUMBER(10,0) and NUMBER(38,0) because TRY_CAST, like every TRY_ conversion function, only accepts VARCHAR or CHAR input. A NUMBER or VARIANT column must become a string first, as in TRY_CAST(col::VARCHAR AS NUMBER(38,0)), or use plain CAST when a failed conversion should stop the query.

  • Applies to Snowflake SQL (current release, Nov 2026), TRY_CAST and TRY_TO_* conversion functions
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Ask Snowflake for the type of the expression you pass in. Anything other than VARCHAR or CHAR explains the error; the result also tells you which cause below applies.

Run this first
SELECT SYSTEM$TYPEOF(amount) FROM orders LIMIT 1;

Then find the line you see in this list and open its fix:

  1. 1The input column already has a typed value, such as NUMBER or DATESYSTEM$TYPEOF returns NUMBER, FLOAT, DATE or a timestamp type, matching the first type named in the error
  2. 2The input is a VARIANT value from JSON or another semi-structured columnSYSTEM$TYPEOF returns VARIANT, usually for an expression like payload:amount

What does the error look like?

  • 001065 (22023): SQL compilation error:
  • Function TRY_CAST cannot be used with arguments of types NUMBER(10,0) and NUMBER(38,0)
  • Function TRY_CAST cannot be used with arguments of types DATE and TIMESTAMP_NTZ()

Cause 1 of 2

The input column already has a typed value, such as NUMBER or DATE

You seeSYSTEM$TYPEOF returns NUMBER, FLOAT, DATE or a timestamp type, matching the first type named in the error

Check

TRY_CAST cannot be used with arguments of types NUMBER or DATE because its usage notes say it works only for string expressions. Switching to TRY_TO_NUMBER does not help: Snowflake's error-handling conversion functions all take VARCHAR or CHAR input only. Snowflake's own Snowpark library hit the DATE case and fixed it by turning the input into a string first.

Check
DESCRIBE TABLE orders;

Fix

If a bad value should fail loudly, use CAST or the :: operator on the typed column. If you want NULL for values that do not fit, turn the value into text first and keep TRY_CAST, as in this NUMBER example.

Fix
-- fail on bad values
SELECT amount::NUMBER(10,0) FROM orders;

-- NULL on bad values
SELECT TRY_CAST(amount::VARCHAR AS NUMBER(10,0)) FROM orders;

Verify

The query runs, and rows whose value cannot fit come back as NULL in the TRY_CAST version.

Verify
SELECT COUNT(*) FROM orders WHERE TRY_CAST(amount::VARCHAR AS NUMBER(10,0)) IS NULL;

Confirmed by docs.snowflake.com

Did this fix it?

Cause 2 of 2

The input is a VARIANT value from JSON or another semi-structured column

You seeSYSTEM$TYPEOF returns VARIANT, usually for an expression like payload:amount

Check

Snowflake's semi-structured guide says the : operator and the . and [] after it always return VARIANT values, even when the value inside is a string. The conversion functions overview states that TRY_ functions only support string expressions as input, so the element has to be cast to a string before TRY_CAST or TRY_TO_NUMBER can read it.

Check
SELECT SYSTEM$TYPEOF(payload:amount) FROM events LIMIT 1;

Fix

Cast the element to VARCHAR inside the call. Snowflake also warns that TRY_ functions used with VARIANT data can be slower, so convert once in a staging view rather than in every query.

Fix
SELECT TRY_TO_NUMBER(payload:amount::VARCHAR, 38, 2) AS amount
FROM events;

Verify

Numeric strings come back as numbers, and malformed ones as NULL, without the error.

Verify
SELECT payload:amount, TRY_TO_NUMBER(payload:amount::VARCHAR, 38, 2) FROM events LIMIT 20;

Confirmed by docs.snowflake.com

Did this fix it?

How do I stop it coming back?

  • Keep TRY_CAST for raw text columns in staging models, and cast typed columns with CAST in later layers.
  • When a shared SQL macro wraps TRY_CAST, convert its input to VARCHAR inside the macro so a column that becomes numeric upstream does not break it.
  • Check column types with DESCRIBE TABLE after any source schema change before rerunning downstream models.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.