简体   繁体   English

AWS Athena:正确的功能

[英]AWS Athena: Right function

I would like to use the function right from AWS athena, but it does not seem to be supported.我想right从 AWS athena 使用该功能,但似乎不受支持。

How would I go about and trimming certain characters in Athena?我将如何处理和修剪 Athena 中的某些角色?

For example I would like to do RIGHT('1313521521', 4)例如我想做RIGHT('1313521521', 4)

to get 1521 .得到1521 Unfortunately I would get something like不幸的是,我会得到类似的东西

Queries of this type are not supported

Athena uses Presto as SQL engine and it does not have right function, but you can mimic it using substr and determining the staring position greatest(length(str) - 3, 1) - we need to start from 4th from last index, if string is too short - start from 1st index, cause Presto indexes starting from 1): 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

Output:输出:

_col0 _col0
id1 id1
1521 1521

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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