Showing posts with label SKIP. Show all posts
Showing posts with label SKIP. Show all posts

Saturday, November 14, 2015

1.23 COPY : Skipping Rows,bytes while loading data.

COPY : Skipping Rows,bytes while loading data.

The COPY statement has two options to skip input data.

The SKIP BYTES option is only for fixed-width data loads:

SKIP BYTES total
Skips the total number (integer) of bytes from the input data.
SKIP records
Skips the number (integer) of records you specify.
SKIP works with both delimited and fixed width files.

Following examples shows how to skip 1st record in the file.

<> /home/sukul1 $ cat employeedet3.dat
rahul,dravID       ***2010-01-01100000
SAURAV,GANGULY     ***2010-10-01200000


sukul1=> COPY USER_30_DAY_TABLES.EMPLOYEE_1
sukul1-> (
sukul1(> NAME,
sukul1(> AGE NULL '***',
sukul1(> JOINING_DATE FILLER VARCHAR(10),
sukul1(> JOINING_YEAR AS TO_NUMBER(TO_CHAR(TO_DATE(JOINING_DATE,'YYYY-MM-DD'),'YYYY')),
sukul1(> SALARY
sukul1(> )
sukul1-> FROM LOCAL '/home/sukul1/employeedet3.dat'
sukul1-> FIXEDWIDTH COLSIZES(19,3,10,6)
sukul1-> SKIP 1
sukul1-> DIRECT;
 Rows Loaded
-------------
           1
(1 row)

sukul1=> select * from USER_30_DAY_TABLES.EMPLOYEE_1;
        NAME         | AGE | JOINING_YEAR | SALARY
---------------------+-----+--------------+--------
 SAURAV,GANGULY      |     |         2010 | 200000
(1 row)


Sunday, November 8, 2015

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.