New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add build in TRY_CAST function [CORE5378] #5651
Comments
Commented by: @dyemanov create function try_cast_to_int(param varchar(32000)) |
Commented by: @livius2 Yes Dmitry - i know new psql function feature |
Commented by: @asfernandes I'd say it makes no sense such function, but if you want you can do it manually. |
Commented by: @livius2 i suppose that MSSQL will do not contain it if it is not usefull... |
Commented by: @asfernandes Why in the world someone would try to get a data and ignore it not knowing if it was null or something completely different? |
Commented by: @livius2 e.g. external table data you try to import CASE WHEN TRY_CAST(X AS INTEGER) THEN 'INTEGER' ---------------------------- size of product e.g. you have data with: and you then can select * FROM PRODUCTS WHERE TRY_CAST(SIZE AS Integer) IS NOT NULL select * FROM PRODUCTS WHERE TRY_CAST(SIZE AS Integer) IS NULL ----- .... |
Commented by: @asfernandes I think you're asking for wrong function. Something like IS_TYPE would be much better for the problems you presented. |
Commented by: @dyemanov I tend to close this ticket as rejected. Otherwise I'm afraid we may end discussing try_substring_for_non_string(), try_add_non_numbers(), etc. |
Commented by: @livius2 Dmitry - do not explode it one more sample: You design your query and you have it like: and you query run into error beacuse cast - how do you find the problem? select try_CAST(some concatenation as Integer) FROM SOME_SELECT PS1> https://msdn.microsoft.com/en-us/library/hh974669.aspx |
Submitted by: @livius2
Will be good to see TRY_CAST function.
It is similar to normal CAST
but when cast is not possible then TRY_CAST return NULL instead like normal CAST throw error
usage:
SELECT TRY_CAST('XYZ' AS INTEGER), TRY_CAST('123' AS INTEGER) FROM RDB$DATABASE
result:
NULL, 123
The text was updated successfully, but these errors were encountered: