【问题标题】:How to get second or first part of email address in Amazon Redshift?如何在 Amazon Redshift 中获取电子邮件地址的第二部分或第一部分?
【发布时间】:2019-09-27 15:11:02
【问题描述】:

我的表格中有一个列用于保存电子邮件地址。

  1. 如何选择它的第一部分('@'之前)?
  2. 如何选择它的第二部分(在“@”之后)?
  3. 下面的WHERE 语句在 Redshift 中做了什么(email_add 是保存表中电子邮件地址的列)?

    SELECT blablabla WHERE SUBSTRING(email_add,1,DECODE(POSITION('@' IN email_add),0,2,POSITION('@' IN email_add)-1)) IN ('arzt','zahnarzt','heilpraktiker','orthopaed','facharzt','praxis','gynaekol','klinik')

【问题讨论】:

    标签: sql amazon-redshift


    【解决方案1】:

    对于 1 和 2,split_part(在分隔符处拆分字符串并返回给定字段(从 1 开始计数)。https://www.postgresql.org/docs/9.1/functions-string.html

    SELECT split_part('abc@def.com', '@', 1); -- abc
    SELECT split_part('abc@def.com', '@', 2); -- def.com
    

    【讨论】:

    • 红移 postgres。但在这种情况下,解决方案有效。您应该参考 docs.aws.amazon.com/redshift/latest/dg/SPLIT_PART.html 而不是 postgres 文档。
    • 谢谢你们!如果我像你一样直接给出列名而不是字符串('abd@def.com'),这是否有效?所以我用 email_add 替换它(email_add 是包含电子邮件地址的列的名称)?
    • 是的。使用字符串文字更容易演示。
    猜你喜欢
    • 1970-01-01
    • 2013-02-19
    • 2022-07-14
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2021-02-12
    相关资源
    最近更新 更多