How To: Bulk Loading a CSV Into an Existing Table

This document explain how to load the CSV into the cloud when using SQL Workbench (or other similar tool)

Syntax

COPY [schema_name].table_name [ ( column_name [, ... ] ) ]
        FROM 'filename'
        [ [ WITH ] ( option [, ...] ) ]
        ;

    with option can be one of:
        DIRECTORY
        OFFSET N
        LIMIT N
        DELIMITER 'delimiter'
        RECORD DELIMITER 'record delimiter'
        ERROR_LOG 'error_log_filename'
        ERROR_VERBOSITY { 0 | 1 }
        STOP AFTER N ERRORS
        PARSERS { '[column_name=parser_format, ...]' }
Files/Directory:

Example

This command will copy data from a CSV file into the table called 'customers', and will output the error log if necessary to the specified error log.

COPY public.customers FROM'/home/user1/demo/customers.csv'
WITH delimiter '|'
error_log '/home/user1/demo/logs/customers.log'
error_verbosity 1;

See also Best Practices when loading files to tables

  • 11
  • 05-Jan-2018
  • 849 Views