-1

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']"

1

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

When I use it in the stored procedure of language "JavaScript". It is giving me the error Execution error in store procedure SAMPLE: Unsupported feature '|'. At Statement.execute, line 22 position 31
Given this question was "how do I make this SQL work" this question has been answered, As to "how do I make valid SQL still valid when I embed it in a JavaScript stored procedure" that is another question. And I have given some guidance of that question also.
1

Double $$ makes escaping easier. Combine that with translate and you could do

select translate('[\'Customers NY\']',$$[']$$,'');

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.