【问题标题】:import data from CSV into a Postgres table using pgAdmin 3使用 pgAdmin 3 将数据从 CSV 导入 Postgres 表
【发布时间】:2014-12-17 00:32:47
【问题描述】:
COPY des_unificado (cedula, grupo, nivel, insti, sector, dpto, zona, ccorres, apel_corto, digito_id, nombre, cargo, pres_act, turno, tipo_rubro, catego_psp, cant_rubro, presupuesto_ant, devenga_ant, aporte_ips, aporte_bnt, ac_meses, ac_aguinal, f_mm_ing_c, f_aa_ing_c, opera_lqd, tipo_rgtro, status_crg, aa_plan, mm_plan, jubilac, rec_ant, ccorr, orden, antece_nro, resolu_nro, estado, insti_ant, id_grado_c, seccion, id_especia, multa, judicial, afemec, otros_dec, presupuesto, afemec_1, liquido, dcto_jub, monto_defi, aux, linea)
FROM '/home/arturo/Escritorio/des_unificado1.csv' 
WITH DELIMITER ';'
CSV HEADER

谁能帮帮我,当你运行这些命令时,我收到以下错误:

ERROR:  could not open file "/home/arturo/Escritorio/des_unificado1.csv" for reading: No such file or directory

********** 错误**********

ERROR: could not open file "/home/arturo/Escritorio/des_unificado1.csv" for reading: No such file or directory
SQL state: 58P01

【问题讨论】:

  • 正如错误提示的那样,您是否看到/home/arturo/Escritorio/des_unificado1.csv 确实存在?通过 ls /home/arturo/Escritorio/des_unificado1.csv 验证文件是否存在
  • 你需要包含更多信息——你以什么用户身份运行命令,你在什么机器上运行命令,postgres在什么机器上运行,权限是什么,所有者和组您要导入的文件?
  • 告诉我不存在文件,但如果我在桌面上有它@karthikr
  • @EdKing 你能帮我吗,我非常需要一个答案
  • 如果它告诉你文件不存在,你需要先解决这个问题。您是要复制数据库还是数据库?

标签: python database postgresql csv import


【解决方案1】:

COPY 期望文件位于数据库服务器,而不是数据库客户端。因此,如果您要连接到另一台计算机上的服务器并且文件在您的计算机上,则该服务器不存在该文件。

如果您希望文件位于数据库客户端,可以使用psql 命令\copy。有关详细信息,请参阅\?

这是psql 命令行客户端的一部分,而不是服务器。它在内部使用COPY ... FROM STDIN 并读取文件,然后通过 PostgreSQL 连接将其发送到服务器。

【讨论】:

  • @Matias 在psql 中使用\copy
  • 你能给我你的邮箱吗,我想发截图@karthikr
  • 你能给我你的邮箱吗,我想发截图@craig-ringer
  • 您只需粘贴一个链接即可上传图片。
  • @Matias 你似乎没有在听。您的屏幕截图显示您正在通过 pgadmin 使用 COPY。在psql 中使用\copy。如果你使用 pgadmin,你没有\copy。您必须改为使用 pgadmin 的“import”命令,或使用 psql 命令行客户端。
猜你喜欢
  • 2013-10-24
  • 2022-07-01
  • 1970-01-01
  • 2020-07-28
  • 1970-01-01
  • 1970-01-01
  • 2019-05-15
  • 2020-04-26
  • 1970-01-01
相关资源
最近更新 更多