3

I have a procedure in Postgres which is doing just fine. It is storing data in a database table which you can use them later. One column in the database table stores names of customers. Some of the names have special chars such as apostrophe '. How can I replace this character with an empty string in Postgres?

UPDATE 
   booking
SET 
   name= REPLACE(name,"'",'')
WHERE 
   booking_id = 1;
1
  • 1
    That sounds as if you are using string literals incorrectly. Please Edit your question and add the code of your function Formatted text please, no screen shots. edit your question - do not post code or additional information in comments. Commented Nov 11, 2017 at 8:03

2 Answers 2

5

Here is what i got the solution I used the replace function from postgres function list in my query and worked like a charm.The REPLACE function takes in three params,the first is the table column you want to replace,the second param is the pattern match you want to replace and the third param is the character to replace the ones you don't want

    SELECT replace([table_column],'''','') as name from table_name WHERE [condition]
Sign up to request clarification or add additional context in comments.

Comments

2

You could use REPLACE:

UPDATE table_name
SET name = REPLACE(name, '''', '')
WHERE name LIKE '%''%';

Rextester Demo

5 Comments

I have tried to use that but am getting error something like ' column "'" does not exist' seems like it is only for table columns,right??
To me i want to replace say the name O'Neil to ONeil not the column name
@laroja show the exact query you have run. The query from this answer cannot trigger the error you provided.
@zerkms this is the query UPDATE customer SET name= REPLACE(name,"'",'') WHERE booking_id =1;
@laroja if you check the answer again you'd spot there are no double quotes " there, all those are single quotes '

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.