postgresql中复制命令出错?

时间:2015-05-13 08:22:52

标签: postgresql postgresql-copy

我的命令是

\copy meta.amz_payment1("Date", settlement_id, type, order_id, sku, 

description, quantity, marketplace, fulfillment, order_city, order_state, 

order_postal, product_sales, shipping_credits, promotional_rebates, 

sales_tax_collected, selling_fees, fba_fees, other_transaction_fees,other, total) 

from '/Users/manish/Downloads/amz.csv' delimiter ',' csv header

但它会出现以下错误:

  

错误:数字类型的输入语法无效:“ - 8,791.41”语境:   COPY amz_payment1,第23行,列总数:“ - 8,791.41”

1 个答案:

答案 0 :(得分:1)

“total”列的类型为numeric,但CSV文件具有该位置的格式化字符串。您应该在varchar表中添加meta.amz_payment1列,并将信息复制到该列中。复制数据后,可以使用UPDATE语句填充“total”列:

ALTER TABLE meta.amz_payment1 ADD COLUMN total_fmt varchar;

\copy meta.amz_payment1("Date", ... total_fmt) from ...;

UPDATE meta.amz_payment1 SET total = total_fmt::numeric;

然后

ALTER TABLE meta.amz_payment1 DROP COLUMN total_fmt;