Home > Net >  How to remove characters from a string when flattening?
How to remove characters from a string when flattening?

Time:07-19

I have the following array as a record:

[
  "['Customer service', 'Ux/Ui']"
]

How can I remove []'' characters to get only the string Customer service, Ux/Ui?

I used lateral flatten as below, but still returns it with []

select regexp_replace(value::varchar, '[[]'']', '') as label_cleaned
from t1,
 lateral flatten(input => label)

CodePudding user response:

I think it's about the missing escape characters:

with MyData as (
select ['[''Customer service'', ''Ux/Ui'']'] as label )
select regexp_replace(value::varchar, '[\\[\\]'']', '') as label_cleaned
from MyData,
lateral flatten(input => label)

As you can see I added backslash symbols.

  • Related