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}$' 
1
  • 1
    replace NOT REGEXP with !~. You can shorten the regex pattern further to ^\d{12}$ Commented Nov 9, 2017 at 16:56

2 Answers 2

5

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

UPDATE
    customer_details 
SET 
    customer_no = NULL 
WHERE 
    customer_No !~ '^[[:digit:]]{12}$';
Sign up to request clarification or add additional context in comments.

Comments

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}$' 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.