6

I have addresses like this

420 CONSUMER SQUARE (PET SMART PARKING LOT) 

in a column and I want to remove the brackets and the word in that and the result should look like

420 CONSUMER SQUARE

How can I do this in PostgreSQL?

2 Answers 2

13

Please try this

SELECT regexp_replace('420 CONSUMER SQUARE (PET SMART PARKING LOT)', '\(.*\)', '');

Sign up to request clarification or add additional context in comments.

Comments

2

You need to use regexp_replace function

SELECT regexp_replace('420 CONSUMER SQUARE (PET SMART PARKING LOT)', '^(.*)\\(.*?\\)', '\\1')
-- or
SELECT regexp_replace('420 CONSUMER SQUARE (PET SMART PARKING LOT)', '\\(.*?\\)$', '')

Both examples will return 420 CONSUMER SQUARE

5 Comments

I have lots of this in a column with different address name so where can i put the column name in this ??
@DeepanKaviarasu SELECT regexp_replace(address_column_name, '\\(.*?\\)$', '')
"SELECT ColumnName, (regexp_replace(ColumnName, '\(.*?\)$', '')) from TableName " will this work ??
10 NO WHITE HORSE PK (PARKING, New Jersey - What should I do if column has single open bracket like this example ??
@Vaishali I tested it on the exactly same version (9.3.5). What does it show when you run the query above?

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.