1

I have a function that generates a new user in the database. I would like to check if the email address contains any quotes and if it does, I would like to duplicate them.

For example, I have the following email address: test.o'[email protected] and I would like to transform it into test.o''[email protected].

Could anybody help me with this? Thank you

1 Answer 1

2

Assuming you expect only one single quote (and not double or more), you could try using a simple replace:

UPDATE yourTable
SET email = REPLACE(email, '''', '''''');
Sign up to request clarification or add additional context in comments.

5 Comments

Maybe for better reading and understanding you can use double quotes like : REPLACE(email, "'", "''")
@ErgestBasha OK, but I won't quote you on that :-) ... Double quotes may not be supported by all SQL engines, so I tried to give an answer that is as ANSI-friendly as possible.
@ErgestBasha, doesn't Postgresql read "'" as a column name?
Anyway, I'd add WHERE email LIKE '%''%', to keep transaction size down.
@jarlh you are right I didn't notice PostgreSQL tag

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.