question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation for try and try_cast not clear for cast errors

See original GitHub issue

it appears that try() and try_cast() are not handling invalid type cast errors. Here is what I’m seeing on the teradata sandbox vm

presto> select try(cast(0.01 as date)); Query 20170217_090614_00041_fchrk failed: line 1:12: Cannot cast decimal(2,2) to date select try(cast(0.01 as date))

and try_cast()

presto> select try_cast(0.01 as timestamp); Query 20170217_084646_00032_fchrk failed: line 1:8: Cannot cast decimal(2,2) to timestamp select try_cast(0.01 as timestamp)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
electrumcommented, Feb 17, 2017

I see the confusion with the documentation. It says returns null if the cast fails which means fails at runtime. That’s different than the cast not existing, but it’s easy to misinterpret. We can make the documentation more explicit.

0reactions
stale[bot]commented, Apr 7, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TRY_CAST (Transact-SQL) - SQL Server - Microsoft Learn
The following example demonstrates that TRY_CAST returns an error when the cast is explicitly not permitted. SQL Copy. SELECT TRY_CAST( ...
Read more >
15.10 - TRYCAST - Teradata Database
Purpose TRYCAST takes a string and tries to cast it to a data type specified after the AS keyword (similar to CAST).
Read more >
How do try_cast error handling in a query with long results
On your question, I'm not sure I follow. TRY_CAST won't error; that's the point. It will return NULL if the value can't be...
Read more >
SQL Server TRY_CAST Function
The TRY_CAST() function takes the input value and tries to cast it to a value of the specified data type. It returns the...
Read more >
PostgreSQL alternative to SQL Server's `try_cast` function
The extra cast to text means extra cost (though not much). ... Here's a generic try-cast, probably very slow. ... Let's assume an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found