简体   繁体   中英

Importing a csv file into postgresql

I have a *.csv file which I want to import into my database. basically it looks like that:

2013.11.07,11:50,1.35163,1.35167,1.35161,1.35163,15
2013.11.07,11:51,1.35166,1.35173,1.35165,1.35170,21
2013.11.07,11:52,1.35170,1.35170,1.35163,1.35163,11

I am using:

DROP TABLE table;

CREATE TABLE table
(
id SERIAL primary key,
Date Date,
Time Time,
Open double precision, 
High double precision, 
Low double precision,
Close double precision,
Volume bigint
);

COPY table FROM 'C:\\Users\\user\\EURUSD1.txt' DELIMITER ',' CSV;

However I am getting at the Date:

ERROR: invalid input syntax for integer: "07/11/2013" CONTEXT: COPY eurusd_m1, line 1, column id: "07/11/2013"

I really appreciate your help on how to fix that?

Just because id is serial doesn't mean it's disregarded when loading - you should be specifying your columns in your copy statement, eg

COPY table (Date, Time, Open, High, Low, Close, Volume)
  FROM 'C:\\Users\\user\\EURUSD1.txt' DELIMITER ',' CSV;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM