You seem to be using Java and JDBC. Read the JDBC tutorial that describes how to use parameterized queries to safely insert data without risking SQL injection problems .
Read the JDBC tutorial's prepared instructions section and these simple examples in different languages, including Java .
Since you have backslashes and not just 'single quotes' problems, I would say that you use PostgreSQL 9.0 and older, the default is standard_conforming_strings = off . In newer versions, the backslash is only special if you use the PostgreSQL E'escape strings' extension. (That's why you always include your version of PostgreSQL in questions ).
You can also learn:
Although you can explicitly specify values, this happens with an error that is slow and ineffective. You must use parameterized queries (prepared statements) to safely insert data.
In the future, please include the code snippet you came across and information about the language you use, version of PostgreSQL, etc.
If you really need to manually delete the lines, you need to make sure that standard_conforming_strings included and double quotes, for example don''t manually escape text ; or use PostgreSQL-specific E'escape strings where you \'backslash escape\' quotes' . But in fact, use prepared statements, itβs easier.
source share