I am trying to make a query on AWS Athena, where I want to filter only numeric entries from a varchar column. However, Athena does not support ISNUMERIC function. I saw some functions that would be useful, but they are available only for Amazon Redshift and not for AWS Athena. Is there any way to apply this type of filter on Athena? Thank you.
Asked
Active
Viewed 8,133 times
2 Answers
10
You can do this with try()
:
...
WHERE try(CAST(my_column AS double)) IS NOT NULL

Piotr Findeisen
- 19,480
- 2
- 52
- 82
-
You can also use `try_cast`: `WHERE try_cast("my_column" AS double) IS NOT NULL` – Marcin Jul 02 '22 at 04:06
5
You can use regexp_like
:
…
WHERE regexp_like(my_column, '^-?\d+$')
This would match positive and negative integers, if you want to match decimals you need a more complex pattern, of course.

Theo
- 131,503
- 21
- 160
- 205