2

I'm trying to build a regex to match multiple characters in order to replace them.

I have a PHP-working pattern which looks like :

/([\{\}\"])*/g

But unfortunately, it doesn't seem to work with Postgres.

Could someone help please ?

Here's the request I'm trying to build :

SELECT 
   regexp_replace(array_agg(DISTINCT columnName)::TEXT, '/([\{\}\"])*/g', '')
FROM tableName
WHERE ...
0

1 Answer 1

4

Not sure what the / and /g are in your regex, if that is a delimiter and the "global" flag, then you can't specify that inside the regex in Postgres. In Postgres that would be an extra parameter to the function:

regexp_replace(array_agg(DISTINCT columnName)::TEXT, '([\{\}\"])*', '', 'g')

but it looks like you are trying to concatenate strings. If that is true, I think you actually want:

string_agg(distinct columnName, '') 
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, didn't know about string_agg. Thanks !

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.