简体   繁体   English

如何使用“psql”解决“错误:列缺少数据”?

[英]How do I solve "ERROR: missing data for column" with "psql"?

I have a makefile in which I am trying to copy the output of a Python program into a table hosted on my PostgreSQL server.我有一个 makefile,我试图在其中将 Python 程序的输出复制到我的 PostgreSQL 服务器上托管的表中。

My query looks something like this:我的查询看起来像这样:

Python3 filter.py | psql -X -U $(DBUSER) -d $(DBNAME) -h $(DBHOST) -p $(DBPORT) -1 -e \
   -c "COPY table1(col1, col2) FROM STDIN with (format csv, header true, delimiter '|')"

However, when I execute it I get the following error message:但是,当我执行它时,我收到以下错误消息:

ERROR:  missing data for column "col1"
CONTEXT:  COPY table1, line 168061: ""

To try and understand the issue, I exported the output of the Python program to a CSV file and I realized that the issue comes from the fact that there are no more entries after line 168060. So line 168061 is indeed empty.为了尝试理解这个问题,我将 Python 程序的输出导出到一个 CSV 文件,我意识到这个问题来自于第 168060 行之后没有更多条目的事实。所以第 168061 行确实是空的。

I have tried using the NULL option for COPY but it did not work, I get the same error.我曾尝试将NULL选项用于COPY但它没有用,我得到了同样的错误。

I also managed to import into table1 the content of the physical CSV file using a very similar COPY statement.我还设法使用非常相似的COPY语句将物理 CSV 文件的内容导入table1 This works, but my objective would be to achieve this without having to create a file.这行得通,但我的目标是在无需创建文件的情况下实现这一目标。

Any ideas?有任何想法吗?

解决方案是更改filter.py以使其不输出有问题的空行。

thank you all for your answers,谢谢大家的答案,

Indeed I simply did an easy modification in the filter.py and it works now.事实上,我只是在 filter.py 中做了一个简单的修改,现在它可以工作了。 I was just too focused on doing it in during the import with PSQL.在使用 PSQL 导入期间,我太专注于做这件事了。

Cheers :)干杯:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决此问题以使用 psql? | psql:错误:致命:角色“postgres”不存在 - How do I solve this problem to use psql? | psql: error: FATAL: role "postgres" does not exist 错误:在 psql 中使用 \copy 时缺少列数据 - ERROR: missing data for column when using \copy in psql 错误:在 psql 中使用 COPY FROM PROGRAM 时缺少列数据 - ERROR: missing data for column when using COPY FROM PROGRAM in psql 如何解决 psql 错误:无法连接到服务器? - How to solve psql error: could not connect to server? 如何在 psql 中设置最大列宽? - How do I set maximum column width in psql? 当Hawq投诉以下内容时,我该如何解决错误:缺少“ SoldToAddr2”列的数据 - How do i resolve error when Hawq complaints for : missing data for column “SoldToAddr2” 在 Postgresql 中打开 psql 时出现“权限被拒绝”重复出现的错误。为什么会出现此错误?如何解决? - I am geting a recurring error as “permission denied” on opening psql in Postgresql.Why am i getting this error?How to solve it? 如何解决 psql 的错误:Argument list too long - How to solve the error of psql: Argument list too long 我尝试添加的新列数据的 PSQL/Spring Boot 类型语法错误 - PSQL/Spring Boot type syntax error for new column data that I am trying to add 如何修复此错误:psql: /usr/pgsql-13/lib/libpq.so.5: 没有可用的版本信息(psql 需要)? - how do I fix this error: psql: /usr/pgsql-13/lib/libpq.so.5: no version information available (required by psql)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM