2

This query works in mysql but I am not sure how to write the same query in redshift / postgresql.

update customer_Details set
customer_No = NULL
WHERE customer_No NOT REGEXP '^[[:digit:]]{12}$' 
Michel Milezzi
  • 10,087
  • 3
  • 21
  • 36
shantanuo
  • 31,689
  • 78
  • 245
  • 403

2 Answers2

5

You need to use !~ operator. Something like this should work:

UPDATE
    customer_details 
SET 
    customer_no = NULL 
WHERE 
    customer_No !~ '^[[:digit:]]{12}$';
Michel Milezzi
  • 10,087
  • 3
  • 21
  • 36
2

Redshift is basically a fork of postgres 8.3, and it uses postgres's regex syntax:

update customer_Details set
customer_No = NULL
WHERE customer_No ! ~ '^[0-9]{12}$' 
Bohemian
  • 412,405
  • 93
  • 575
  • 722