A common question I’ve received from new Vertica users is, “How do I enter newlines into a string literal, or use other backslash sequences like ‘t’?” This is especially common from users transitioning from systems like MySQL that do not use SQL standard-conforming string literals, or from users of older, pre-4.0 versions of Vertica (which allowed backslash sequences in regular string literals). There are two different methods for using backslash sequences in strings:
Method #1: Extended String Literals
This is the preferred method and is very easily implemented. Simply add an “E” prefix to your string literal to enable handling of backslash sequences in the string.
SELECT 'Footbarnbaz'; -- Does not work, backslashes not interpreted SELECT E'Footbarnbaz'; -- Works
Method #2: Disable the “standard_conforming_strings” Option
You can also disable this feature, either per session or globally. This is helpful for users that are upgrading from older, pre-4.0 versions of Vertica or have legacy code that cannot be modified. By default, Vertica will still issue warnings if backslash sequences are found in regular string literals, so there’s a second option, “escape_string_warning”, that you can also disable to suppress these warnings.
To disable per session:
SET standard_conforming_strings TO off; SET escape_string_warning TO off; SELECT 'Footbarnbaz'; -- Works
To disable globally, for all sessions:
SELECT SET_CONFIG_PARAMETER('StandardConformingStrings', '0'); SELECT SET_CONFIG_PARAMETER('EscapeStringWarning', '0'); SELECT 'Footbarnbaz'; -- Works