【问题标题】:using regular expressions in redshift在 redshift 中使用正则表达式
【发布时间】:2017-11-09 16:51:24
【问题描述】:

此查询在 mysql 中有效,但我不确定如何在 redshift / postgresql 中编写相同的查询。

update customer_Details set
customer_No = NULL
WHERE customer_No NOT REGEXP '^[[:digit:]]{12}$' 

【问题讨论】:

  • NOT REGEXP 替换为!~。您可以将正则表达式模式进一步缩短为^\d{12}$

标签: sql regex amazon-redshift


【解决方案1】:

您需要使用!~ operator。像这样的东西应该可以工作:

UPDATE
    customer_details 
SET 
    customer_no = NULL 
WHERE 
    customer_No !~ '^[[:digit:]]{12}$';

【讨论】:

    【解决方案2】:

    Redshift 基本上是 postgres 8.3 的一个分支,它使用 postgres 的正则表达式语法:

    update customer_Details set
    customer_No = NULL
    WHERE customer_No ! ~ '^[0-9]{12}$' 
    

    【讨论】:

      猜你喜欢
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 2017-01-18
      相关资源
      最近更新 更多