PostgreSQL COPY csv包括引号 [英] PostgreSQL COPY csv including Quotes
问题描述
这是一个非常简单的问题,如下所示,我正在使用psql终端命令COPY
This is a very simple problem, I am using the psql terminal command COPY as shown bellow
COPY tbname FROM '/tmp/file.csv'
delimiter '|' csv;
但是,此file.csv包含诸如
However this file.csv contains data such as
random|stuff|32"
以及
random|other "stuff"|15
我尝试使用双引号将Postgres网站建议的引号转义
I tried to use the double quote to escape the quotes as the Postgres site suggested
random|stuff|32""
random|other ""stuff""|15
这似乎完全删除了我不想要的引号.有没有一种方法可以使导入文件将这些引号视为常规字符,以便它们像在csv文件中一样出现在数据库中?
This seems to remove the quotes completely which I don't want. Is there a way to get the import to just treat these quotes as regular characters so that they appear in the database as they do in the csv file?
推荐答案
According to the documentation, the default quote symbol is ", so you need to provide a QUOTE argument with a different symbol. The quote symbol has to be a single one-byte character.
COPY tbname FROM '/tmp/file.csv'
delimiter '|' QUOTE '}' csv; -- use a symbol you know does not appear in your file.
这篇关于PostgreSQL COPY csv包括引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!