通过CSV从CSV加载PostgreSQL表,并在括号之间添加逗号数据 [英] Load PostgreSQL table from CSV with data with commas between brackets

查看:74
本文介绍了通过CSV从CSV加载PostgreSQL表,并在括号之间添加逗号数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了一些需要加载到PostgreSQL表中的CSV数据,格式如下:

I've been given some CSV data I need to load into a PostgreSQL table with the following format:

7227, {text with, commas}, 10.0, 3.0, text with no commas

我希望我的表格行显示为:

I want my table rows to appear as:

   7227 | text with, commas | 10.0 | 3.0 | text with no commas

如何使用COPY并使其忽略括号之间的逗号?

How can I use COPY and get it to ignore commas between the brackets?

我试图避免对该文件进行预处理,尽管这是一种选择。

I'm trying to avoid pre-processing the file, although that is an option.

推荐答案

恐怕您将不得不编辑该文件。此格式应该可以:

I'm afraid you'll have to edit the file. This format should be ok:

7227, "text with, commas", 10.0, 3.0, text with no commas

或者

7227, text with\, commas, 10.0, 3.0, text with no commas

文档中的原则:


反斜杠字符(\)可用于COPY数据中引用数据
字符,否则这些字符可被用作行或列定界符。
特别是以下字符如果出现在列值中,则必须在其后加上
反斜杠:反斜杠本身,
新行,回车符和当前的定界符。

Backslash characters (\) can be used in the COPY data to quote data characters that might otherwise be taken as row or column delimiters. In particular, the following characters must be preceded by a backslash if they appear as part of a column value: backslash itself, newline, carriage return, and the current delimiter character.

这篇关于通过CSV从CSV加载PostgreSQL表,并在括号之间添加逗号数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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