As documented in String Constants with C-style Escapes, the strings that contain escape sequences with backslashes must start with E
as in E'line1\nline2'
or E'\n'
for a newline alone.
This E
syntax has become mandatory since PostgreSQL 9.1 in its default configuration regarding standard_conforming_strings
, as warned in the doc at the same place:
If the configuration parameter standard_conforming_strings is off, then PostgreSQL recognizes backslash escapes in both regular and escape string constants. However, as of PostgreSQL 9.1, the default is on, meaning that backslash escapes are recognized only in escape string constants.
This behavior is more standards-compliant, but might break applications which rely on the historical behavior, where backslash escapes were always recognized
The quote_literal
function is meant to build SQL statements programmatically before they're fed to the SQL interpreter, that's why its results includes single quotes. This function is not necessary and not helpful for your use case.