Skip to content
Advertisement

AWS Athena: How can we get integer value as string with thousand comma separator in AWS Athena

How can we show integer numbers with thousand comma separator.

So, by executing the below statement

select * from 1234567890

How can we get the result as 1,234,567,890

Advertisement

Answer

You can achieve this by casting number to string and using regex:

with dataset(num) as (
    values (1234567890),
    (123456789),
    (12345678),
    (1234567),
    (123456),
    (12345),
    (1234),
    (123)
)

select regexp_replace(cast(num as VARCHAR), '(d)(?=(ddd)+(?!d))', '$1,')
from dataset

Output:

_col0
1,234,567,890
123,456,789
12,345,678
1,234,567
123,456
12,345
1,234
123
10 People found this is helpful
Advertisement