kb_*_*_14 3 database csv postgresql import
我正在尝试使用“复制”命令将 csv 文件导入到我的 postgres 表中。包含逗号的值已被双引号括起来,但我似乎无法找到使用“复制”命令将它们加载到 postgres 表中而不会出现任何错误的选项。
我正在使用的“复制”命令:
CREATE TABLE candidates (Sno int, name varchar, cases int, case_details varchar, .....);
copy candidates from 'something.csv' with NULL AS ' ' csv ;
Run Code Online (Sandbox Code Playgroud)
有问题的 csv 行示例:
1, "some name", 2, "(1):IPC Sections - 147, 323, 352, 504, 506 , Other Details - Case no.283A/2000, A.C.J.M-5, Ghumangunj Ellahabad, UP, Dt.12.11.2000", .....
Run Code Online (Sandbox Code Playgroud)
case_details属性上方的值中包含逗号。那是我的问题。
对我有用(PG 9.2,linux):
$ cat something.csv
1, "some name", 2, "(1):IPC Sections - 147, 323, 352, 504, 506 , Other Details - Case no.283A/2000, A.C.J.M-5, Ghumangunj Ellahabad, UP, Dt.12.11.2000"
$ psql test
test=> CREATE TABLE candidates (Sno int, name varchar, cases int, case_details varchar);
CREATE TABLE
test=> \copy candidates from 'something.csv' with NULL AS ' ' csv ;
test=> select * from candidates ;
sno | name | cases | case_details
-----+------------+-------+--------------------------------------------------------------------------------------------------------------------------------------
1 | some name | 2 | (1):IPC Sections - 147, 323, 352, 504, 506 , Other Details - Case no.283A/2000, A.C.J.M-5, Ghumangunj Ellahabad, UP, Dt.12.11.2000
(1 row)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7050 次 |
| 最近记录: |