AWS Athena:正确的功能

问题描述 投票:0回答:1

我想使用AWS athena的功能

right
,但似乎不支持。

我将如何处理和修剪《雅典娜》中的某些角色?

例如我想做

RIGHT('1313521521', 4)

获得

1521
。不幸的是我会得到类似的东西

Queries of this type are not supported
sql amazon-athena presto trino
1个回答
2
投票

Athena 使用 Presto 作为 SQL 引擎,它没有

right
功能,但您可以使用
substr
模仿它并确定起始位置
greatest(length(str) - 3, 1)
- 我们需要从最后一个索引的第 4 个开始,如果字符串是太短 - 从第一个索引开始,导致 Presto 索引从 1 开始):

--sample data
with dataset(str) as (
    VALUES ('id1'),
    ('1313521521'),
    ('')
)

-- query
select substr(str, greatest(length(str) - 3, 1))
from dataset

输出:

_col0
id1
1521
 
© www.soinside.com 2019 - 2024. All rights reserved.