postgresql 中使用 PHP 进行 COPY FROM 的问题
我有一些大的 .csv 文件,我正在尝试将其放入数据库中。我正在使用这种结构:
COPY table_name(column1, column2, column..., columnN) FROM stdin;
column1 column2 column... column N
column1 column2 column... column N
column1 column2 column... column N
column1 column2 column... column N
\.
但是在 CLI 中使用 \i 函数之后我得到了:
ERROR: end-of-copy marker corrupt
这不是结束标记的问题,而是编码的问题。如果我在 VIM 中打开这个文件并再次保存它,一切正常,但是如果没有这个操作,我总是收到这个错误。我可以在 PHP 中做什么(使用 PHP 创建这些文件)来解决这个问题?如果这肯定是编码问题?
I have some big .csv files and I am trying to put it into database. I am using this construction:
COPY table_name(column1, column2, column..., columnN) FROM stdin;
column1 column2 column... column N
column1 column2 column... column N
column1 column2 column... column N
column1 column2 column... column N
\.
But after use \i function in CLI I got that:
ERROR: end-of-copy marker corrupt
This is not a problem with end marker, but with encoding. If I open this file in VIM and will save it again, everything is OK, but without this operations I got this error all the time. What can I do in PHP (with PHP I create those files) to fix that? If this is for sure problem with encoding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个简单的解决方案,您只需在“
\.
”后按“Enter
”,然后保存文件并重试,即可解决您的问题。There is a easy solution for this, you only need to press "
Enter
" after "\.
" and then save your file and try again, it will resolve your issue.\.
之后还有换行符吗?检查 PHP 手册中 pg_put_line() 并注意末尾的\n
。Is there also a newline after the
\.
? Check the example in the PHP-manual for pg_put_line() as well and take notice of the\n
at the end.