Vertica Quick Tip: Backslash Sequences in Strings

Vertica Quick Tip: Backslash Sequences in Strings

Josh Varner
//

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

Need Expert Help?

See Our Full Menu of Data Services

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072

×

Love our blog? You should see our emails. Sign up for our newsletter!