postgresql - 错误 : missing data for column when using\copy in psql

标签 postgresql psql postgresql-copy

我正在尝试将 .txt 文件导入 PostgreSQL。 txt 文件有 6 列:

Laboratory_Name Laboratory_ID   Facility    ZIP_Code     City   State

还有 213 行。

我正在尝试使用 \copy 将此文件的内容放入 PostgreSQL 中名为 doe2 的表中,使用以下命令:

\copy DOE2 FROM '/users/nathangroom/desktop/DOE_inventory5.txt' (DELIMITER(' '))

它给我这个错误:

missing data for column "facility"

我四处寻找遇到此错误时该怎么做,但没有任何帮助。有没有其他人遇到过这个?

最佳答案

三种可能的原因:

  1. 文件的一行或多行只有 4 个或更少的空格字符(您的分隔符)。

  2. 一个或多个空格字符已被转义(无意中)。也许在未引用的值末尾有一个反斜杠。对于您使用的(默认)text 格式,the manual explains:

Backslash characters (\) can be used in the COPY data to quote data characters that might otherwise be taken as row or column delimiters.

从具有匹配布局的表中读取时,COPY TOpg_dump 的输出不会出现任何这些错误。但也许您的文件已被编辑或来自不同的错误来源?

  1. 您没有使用您认为正在使用的文件。 psql 命令行界面的 \copy 元命令是 COPY 的包装器,可读取客户端 的本地文件。如果您的文件位于服务器上,请使用 SQL 命令 COPY相反。

关于postgresql - 错误 : missing data for column when using\copy in psql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26747748/

相关文章:

postgresql - 如何在 psql 中获取多个函数?

postgresql csv 复制数据中未加引号的换行符

postgresql - 如何判断 Postgres 中的记录是否已更改

sql - 如何在 PostgreSQL 中转置列和行(即如何切换行和列)?

postgresql - 将 Postgres 聚合函数转换为内联数组

python - Django 原始查询 - 如何将 postgres 数组值作为参数传递?

python - 使用 python tarfile 备份 postgresql 数据目录。预期/忽略哪些错误

python - 如何剖析 Python 数据库代码

c++ - Incomplete parameter error Including postgres.cpp working file in other .cpp 文件

postgresql - 如何在 postgresql 中使用副本时忽略重复键