Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does SELECT TRY_TO_NUMBER('E') return 0?

According to Snowflake documentation, TRY_TO_NUMBER should return NULL when passed a non-numeric value. However, when passing the string ‘E’, the function returns a 0.

SELECT TRY_TO_NUMBER('E');

Result showing 0 instead of expected NULL

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

because there is an implicit zero in front and after it:

SELECT TRY_TO_NUMBER('E'),
    TRY_TO_NUMBER('1E2'),
    TRY_TO_NUMBER('0E'),
    TRY_TO_NUMBER('0E0');

gives:

TRY_TO_NUMBER(‘E’) TRY_TO_NUMBER(‘1E2’) TRY_TO_NUMBER(‘0E’) TRY_TO_NUMBER(‘0E0’)
0 100 0 0

probably much like 010.0 and 10 and 10.0` all parse to the same thing, the zero’s are not required.

But it does seems like a failure of the parser.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading