【问题标题】:Proper Case in Athena SQLAthena SQL 中的正确案例
【发布时间】:2021-09-09 17:32:53
【问题描述】:

我是 Athena 的新手,正在尝试将字段“国家/地区”转换为正确大小写。例如:

美国 -> 美国

有没有办法在 Athena 中做到这一点?

【问题讨论】:

  • 你能在表示层转换成初始大写吗?这就是它应该完成的地方。此外,为国家/地区使用 ISO 3166-1 alpha-3 并在表示层中进行翻译可能是有意义的,以防国家/地区更改其名称。
  • 是的。我能够做类似的事情: select * from (SELECT split(country,' ') as result FROM "leads_db"."test_leads") where lower(element_at(result,1)) = element_at(result,1)或更低(element_at(结果,2))= element_at(结果,2);但这似乎效率不高
  • 这只是一个想法。我的想法是将我得到的列表中每个单词的第一个字母大写并将结果连接起来。但我认为应该有一个简单的方法
  • Athena engine version 2's RegEx sectionregexp_replace(string, pattern, function) SELECT regexp_replace('new york', '(\w)(\w*)', x -> upper(x[1]) || lower(x[2])); --'New York' 为例,这对你有用吗?
  • @Abecee 这对我有用.. 非常感谢您的帮助和参考链接

标签: sql amazon-web-services case amazon-athena presto


【解决方案1】:

将评论变成答案:

Athena engine version 2RegEx section 为例
regexp_replace(string, pattern, function)

SELECT regexp_replace('new york', '(\w)(\w*)', x -> upper(x[1]) || lower(x[2])); --'New York'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-24
    • 1970-01-01
    相关资源
    最近更新 更多