如何在Postgres中做简单的csv文件COPY

时间:2016-03-03 20:00:41

标签: postgresql csv

我有:

TAG_ID,TAGNAME,HH_INCEPT,ACCOUNTNUMBER,ACCT_START_DATE,ACCT_STOP_DATE,ORION_CLIENT_TRAIL
45298,JIM JONES,11/16/07,905413871,11/16/07,8/15/14,

我的创建表:

CREATE TABLE folio_groups
(
  id serial NOT NULL,
  tag_id integer NOT NULL,
  tagname character varying(50) NOT NULL,
  hh_incept date NOT NULL,
  accountnumber character varying(50) NOT NULL,
  acct_start_date date NOT NULL,
  acct_stop_date date,
  orion_client_trail integer
)

我试试:

# COPY folio_groups FROM '/tmp/folio.csv' CSV HEADER;

但是得到:

ERROR:  invalid input syntax for integer: "JIM JONE"
CONTEXT:  COPY folio_groups, line 2, column tag_id: "JIM JONE"

知道如何复制这个简单的CSV吗?

1 个答案:

答案 0 :(得分:2)

COPY folio_groups (
  tag_id,
  tagname,
  hh_incept_date,
  accountnumber,
  acct_start_date,
  acct_stop_date,
  orion_client_trail
)
FROM '/tmp/folio.csv' CSV HEADER;