COPY only some columns from input CSV?

I created a table in my database called "con" that has two columns named "date" and "kgs". I am trying to extract data from this file "hi.rpt" copied in this place "H: Sir \ data \ reports \ hi.rpt" and I want to store the values ​​in the table "con" in my database.

I tried this code in pgadmin

When I run:

COPY con (date,kgs) 
FROM 'H:Sir\data\reporting\hi.rpt'
WITH DELIMITER ','
CSV HEADER 
    date AS 'Datum/Uhrzeit'
    kgs  AS 'Summe'

I get an error message:

ERROR: syntax error at or near "date"
LINE 5: date AS 'Datum / Uhrzeit' 
           ^
********** Error **********
ERROR: syntax error at or near "date"
SQL state: 42601
Character: 113

The "hi.rpt" file from which I am reading data looks like this:

Datum/Uhrzeit,Sta.,Bez.,Unit,TBId,Batch,OrderNr,Mat1,Total1,Mat2,Total2,Mat3,Total3,Mat4,Total4,Mat5,Total5,Mat6,Total6,Summe
41521.512369(04.09.13 12:17:48),TB01,TB01,005,300,9553,,2,27010.47,0,0.00,0,0.00,3,1749.19,0,0.00,0,0.00,28759.66
41521.547592(04.09.13 13:08:31),TB01,TB01,005,300,9570,,2,27057.32,0,0.00,0,0.00,3,1753.34,0,0.00,0,0.00,28810.66

20 , "hi.rpt" ?

, ? ?

+4
1

, , COPY , . . :

COPY table_name [ ( column_name [, ...] ) ]
    FROM { 'filename' | PROGRAM 'command' | STDIN }
    [ [ WITH ] ( option [, ...] ) ]

(AS , \d copy psql COPY ).

COPY , CSV. , - // . /, .

PostgreSQL , , COPY, , , CSV , , CSV. , :

COPY con (date,kgs)

PostgreSQL CSV . csv "date" csv "kgs". , CSV, , WITH (FORMAT CSV, HEADER ON) , HEADER.

PostgreSQL 9.4 FROM PROGRAM COPY, , . Python Perl script .

, csv, , date kgs.

COPY , , CSV, INSERT INTO ... SELECT, .

+3

Source: https://habr.com/ru/post/1546508/


All Articles