Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

snowflake regex_replace not working as expected

I am trying to do this that strips "[‘" or "’]" in the string.
For Example, if we have [‘Customer Name’] it should be "Customer Name"

select regexp_replace("['Customers NY']","\\['|\\']","") as customername;

I am getting this error–
SQL compilation error: error line 1 at position 22 invalid identifier "[‘Customers NY’]"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s a typo..

ALL string in SQL are single quotes only.. you double quotes are for named objects like columns/tables.

Then you will have to escape the quotes in the quotes

select regexp_replace('[\'Customers NY\']','\\[\'|\'\\]','') as customername;

gives:

CUSTOMERNAME
Customers NY
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading