Last Updated: February 25, 2016
·
942
· maldonado

Smart string escaping in PostgreSQL

When inserting or updating string (varchar) fields that contains quotes use $$ instead of the regular ' '.

For example:
update table set description = $$ * User's loves "quotes" * $$

In the nasty case that your text contains $ signs, you can define your own tag like this:

update table set description = $escape_tag$ User's loves "quotes" and money $$ $escape_tag$