REPLACE function in snowflake with no pattern match

Viewed 25

I am trying to do below

select replace('abcd.efgh@Domain.com', 'Domain.com', 'ModifyDomain.com')

This means whenever the field value will have "@Domain.com", it should be replaced with "ModifyDomain.com".

Will the original email field value be preserved in case

  1. Original email field value is NULL / BLANK ?
  2. Original email field value does not contain the pattern " Domain.com " ?
1 Answers

Original email field value is NULL / BLANK ? Original email field

If the email field value is NULL or BLANK, it will stay as NULL or BLANK:

select replace( NULL, 'Domain.com', 'ModifyDomain.com'); -- returns null

value does not contain the pattern " Domain.com "?

the original value will return:

select replace('abcd.efgh@Domain.com', 'DomainX.com', 'ModifyDomain.com');
Related