将CSV文件导入PostgreSQL时忽略引号吗? [英] Ignore quotation marks when importing a CSV file into PostgreSQL?

查看:372
本文介绍了将CSV文件导入PostgreSQL时忽略引号吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将制表符分隔的文件导入到我的PostgreSQL数据库中。我文件中的一个字段是标题字段,有时包含实际的引号。例如,我的tsv可能如下所示:

I'm trying to import a tab-delimited file into my PostgreSQL database. One of the fields in my file is a "title" field, which occasionally contains actual quotation marks. For example, my tsv might look like:

id    title
5     Hello/Bleah" Foo

(是的,标题中只有一个引号。)

(Yeah, there's just that one quotation mark in the title.)

当我尝试将文件导入数据库时​​:

When I try importing the file into my database:

copy articles from 'articles.tsv' with delimiter E'\t' csv header;

我收到此错误,引用该行:

I get this error, referencing that line:

ERROR:  unterminated CSV quoted field

如何解决此问题?引号从未用于包围文件中的所有字段。我尝试使用定界符E'\t'Escape从'articles.tsv'复制文章 c'csv标头; ,但在同一行上遇到相同的错误。

How do I fix this? Quotation marks are never used to surround entire fields in the file. I tried copy articles from 'articles.tsv' with delimiter E'\t' escape E'\\' csv header; but I get the same error on the same line.

推荐答案

制表符分隔是复制语句的默认格式,将它们视为CSV只是愚蠢的(您是否仅使用此路径跳过标题?)

Tab separated is the default format for copy statements. Treating them as CSV is just silly. (do you take this path just to skip the header ?)

copy articles from 'articles.tsv';

正是您想要的东西。

这篇关于将CSV文件导入PostgreSQL时忽略引号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆