postgresql - postgresql 中的复制命令出错?

标签 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

但它给出了以下错误:

ERROR: invalid input syntax for type numeric: "-8,791.41" CONTEXT: COPY amz_payment1, line 23, column total: "-8,791.41"

最佳答案

“总计”列的类型为 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;

关于postgresql - postgresql 中的复制命令出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30209420/

相关文章:

postgresql - 如何将表导出为带有 Postgresql 标题的 CSV?

java - 玩!框架 - 无法连接到数据库

postgresql - 将 csv 文件中存在的 NULL 值复制到 postgres

mysql - 使用 shell 脚本将多个表复制到 postgres 数据库

postgresql - 将压缩的 CSV 文件导入 PostgreSQL

python - COPY 是如何工作的,为什么它比 INSERT 快得多?

sql - PostgreSQL 如何排序文本值?

ruby-on-rails - 具有不同仪表板的多个设计用户

postgresql - 测量 PostgreSQL 中的 SQL 执行时间?