Documentation for try and try_cast not clear for cast errors
See original GitHub issueit 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:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.