<p>Attempting to insert an escape character into a table results in a warning. </p>

<p>For example:</p>

<pre><code>create table EscapeTest (text varchar(50));

insert into EscapeTest (text) values ('This is the first part \n And this is the second');
</code></pre>

<p>Produces the warning:</p>

<pre><code>WARNING:  nonstandard use of escape in a string literal
</code></pre>

<p>(<em>Using PSQL 8.2</em>)</p>

<p>Anyone know how to get around this?</p>

[{'answer_id': 938, 'author': 'rjohnston', 'author_id': 246, 'author_profile': 'https://Stackoverflow.com/users/246', 'pm_score': 8, 'selected': True, 'text': "<p>Partially. The text is inserted, but the warning is still generated.</p>\n\n<p>I found a discussion that indicated the text needed to be preceded with 'E', as such:</p>\n\n<pre><code>insert into EscapeTest (text) values (E'This is the first part \\n And this is the second');\n</code></pre>\n\n<p>This suppressed the warning, but the text was still not being returned correctly. When I added the additional slash as Michael suggested, it worked.</p>\n\n<p>As such:</p>\n\n<pre><code>insert into EscapeTest (text) values (E'This is the first part \\\\n And this is the second');\n</code></pre>\n"}, {'answer_id': 943, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 6, 'selected': False, 'text': '<p>Cool.</p>\n\n<p>I also found the documentation regarding the E:</p>\n\n<p><a href="http://www.postgresql.org/docs/8.3/interactive/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS" rel="noreferrer">http://www.postgresql.org/docs/8.3/interactive/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS</a></p>\n\n<blockquote>\n  <p>PostgreSQL also accepts "escape" string constants, which are an extension to the SQL standard. An escape string constant is specified by writing the letter E (upper or lower case) just before the opening single quote, e.g. E\'foo\'. (When continuing an escape string constant across lines, write E only before the first opening quote.) Within an escape string, a backslash character (\\) begins a C-like backslash escape sequence, in which the combination of backslash and following character(s) represents a special byte value. \\b is a backspace, \\f is a form feed, \\n is a newline, \\r is a carriage return, \\t is a tab. Also supported are \\digits, where digits represents an octal byte value, and \\xhexdigits, where hexdigits represents a hexadecimal byte value. (It is your responsibility that the byte sequences you create are valid characters in the server character set encoding.) Any other character following a backslash is taken literally. Thus, to include a backslash character, write two backslashes (\\\\). Also, a single quote can be included in an escape string by writing \\\', in addition to the normal way of \'\'.</p>\n</blockquote>\n'}, {'answer_id': 72132, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Really stupid question: Are you sure the string is being truncated, and not just broken at the linebreak you specify (and possibly not showing in your interface)? Ie, do you expect the field to show as</p>\n<blockquote>\n<p>This will be inserted \\n This will not\nbe</p>\n</blockquote>\n<p>or</p>\n<blockquote>\n<p>This will be inserted</p>\n<p>This will not be</p>\n</blockquote>\n<p>Also, what interface are you using? Is it possible that something along the way is eating your backslashes?</p>\n'}, {'answer_id': 104780, 'author': 'Milen A. Radev', 'author_id': 15785, 'author_profile': 'https://Stackoverflow.com/users/15785', 'pm_score': 2, 'selected': False, 'text': "<p>I find it highly unlikely for Postgres to truncate your data on input - it either rejects it or stores it as is.</p>\n\n<pre><code>milen@dev:~$ psql\nWelcome to psql 8.2.7, the PostgreSQL interactive terminal.\n\nType:  \\copyright for distribution terms\n       \\h for help with SQL commands\n       \\? for help with psql commands\n       \\g or terminate with semicolon to execute query\n       \\q to quit\n\nmilen=&gt; create table EscapeTest (text varchar(50));\nCREATE TABLE\nmilen=&gt; insert into EscapeTest (text) values ('This will be inserted \\n This will not be');\nWARNING:  nonstandard use of escape in a string literal\nLINE 1: insert into EscapeTest (text) values ('This will be inserted...\n                                              ^\nHINT:  Use the escape string syntax for escapes, e.g., E'\\r\\n'.\nINSERT 0 1\nmilen=&gt; select * from EscapeTest;\n          text\n------------------------\n This will be inserted\n  This will not be\n(1 row)\n\nmilen=&gt;\n</code></pre>\n"}, {'answer_id': 2277307, 'author': 'eppesuig', 'author_id': 387880, 'author_profile': 'https://Stackoverflow.com/users/387880', 'pm_score': 3, 'selected': False, 'text': '<p>The warning is issued since you are using backslashes in your strings. If you want to avoid the message, type this command "set standard_conforming_strings=on;". Then use "E" before your string including backslashes that you want postgresql to intrepret.</p>\n'}]
['https://Stackoverflow.com/questions/935', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/246/']