[英]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.