带文字分隔符的Postgres COPY命令 [英] Postgres COPY command with literal delimiter

查看:142
本文介绍了带文字分隔符的Postgres COPY命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 COPY 命令将CSV文件导入到 PostgreSQL 表中. CSV 文件的定界符是逗号(,).但是,还有一个文本字段,其值中带有逗号.例如:

I was trying to import a CSV file into a PostgreSQL table using the COPY command. The delimiter of the CSV file is comma (,). However, there's also a text field with a comma in the value. For example:

COPY schema.table from '/folder/foo.csv' delimiter ',' CSV header

这是 foo.csv 文件的内容:

Name,Description,Age
John,Male\,Tall,30

如何区分文字逗号和定界符?

How to distinguish between the literal comma and the delimiter?

感谢您的帮助.

推荐答案

要使 \ 被识别为转义字符,必须使用文本格式

To have the \ to be recognized as a escape character it is necessary to use the text format

COPY schema.table from '/folder/foo.csv' delimiter ',' TEXT

但是随后还必须删除第一行,因为 HEADER 选项仅对 CSV 格式有效.

But then it is also necessary to delete the first line as the HEADER option is only valid for the CSV format.

这篇关于带文字分隔符的Postgres COPY命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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