SQL COPY table data from CSV file in Postgresql

SQL COPY command examples:

COPY censo.clases_materiales FROM '/home/csv/clases_materiales.csv' DELIMITER ',' CSV;

To ignore the column headers:

COPY catastro_censal.aval_carac_valor FROM '/home/csv/valores-caracteristicas.csv' 
    WITH DELIMITER ';' CSV HEADER;

Define columns to insert (for ignore PK field and postgres takes its sequence as default), also ignore header:

COPY catastro_censal.aval_depreciacion (espec, anios, bueno, regular, malo) 
	FROM '/home/csv/depreciacion.csv' WITH DELIMITER ';' CSV HEADER;

Using TAB character:

COPY censo.json_hclaves FROM '/home/csv/json_hclaves.csv' 
    WITH DELIMITER E'\t' CSV HEADER;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s