Showing posts with label ESCAPE AS. Show all posts
Showing posts with label ESCAPE AS. Show all posts

Sunday, November 8, 2015

1.15 What are special characters and how does copy load then as literals?

COPY: What are special characters and how does copy load then as literals?

The default COPY statement escape key is a backslash (\).

By preceding any special character with an escape character, COPY interprets the character that follows literally, and copies it into the database.

These are the special characters that you escape to load them as literals:
  1. DELIMITER character (default is |)
  1. NULL character (Default is empty string '')
  1. Escape character (Default is  \)
  1. New line and other control characters.

To use a special character as a literal, prefix it with an escape character.
For example, to include a literal backslash (\) in the loaded data (such as when including a file path), use two backslashes (\\).


COPY removes the escape character from the input when it loads escaped characters. 

1.14 COPY : Specifying Load Metadata

COPY : Specifying Load Metadata

In addition to choosing a parser option, COPY supports other options to determine how to handle raw data.

These options are considered load metadata, and we can specify metadata options in different parts of the COPY statement.

Following are the places where we can specify the load metadata:
  1. As a Column or Expression.
  1. As a Column Option.
  1. As a FROM level Option.

Following table shows Which option can be specified at what level.

Metadata Option
As a Column or Expression Option
As a 
COLUMN OPTION
As a FROM 
Level Option
DELIMITER
Y
Y
Y
ENCLOSED BY
Y
Y
Y
ESCAPE AS
Y
Y
Y
NULL
Y
Y
Y
TRIM
Y

Y
RECORD TERMINATOR


Y
SKIP


Y
SKIP BYTES


Y (Fixed-width only)
TRAILING NULLCOLS


Y

Notice that the NULL, ESCAPE,ENCLOSED and DELIMITER (NEED) metadata options can be specified at all the 3 levels.

The following precedence rules apply to all data loads:
  • All column-level parameters override statement-level parameters.
  • COPY uses the statement-level parameter if you do not specify a column-level parameter.

  • COPY uses the default metadata values for the DELIMITER, ENCLOSED BY, ESCAPE AS, and NULL options if you do not specify them at either the statement- or column-level.