Vertica Quick Tip: Backslash Sequences in Strings

Data

Vertica Quick Tip: Backslash Sequences in Strings

by 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

More About the Author

Josh Varner

Database Engineer
Proper Care and Feeding of Vertica (Part One) (This is a multi-part series about the proper care & feeding of a Vertica cluster. There’s simply too much content for one post, ...
Big Changes in Vertica 6.1 SP2 (6.1.2) About a month ago, HP Vertica released its latest service pack, HP Vertica 6.1 Service Pack 2 (version 6.1.2). It may sound like a ...

See more from this author →

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!