简体   繁体   中英

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

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)(?=(\d\d\d)+(?!\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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM