我想将 csv 文件导入 psql db ...
我已经搜索并尝试使用副本,也提到了https://www.commandprompt.com/ppbook/r23528,我使用的语法是:
copy location from 'file.csv' with delimiters '\t' NULL as 'NULL' CSV;
注意:我的 csv 文件由 'tab' 分隔。
第一次执行上述 cmd 后,显示:
ERROR: syntax error at or near ""\t""
LINE 1: ...om 'file.csv' using delimiters "\t" ;
第二次,
ERROR: syntax error at or near "copy"
LINE 2: copy location from 'file.csv' using d...
编辑后,
我第二次尝试使用 like ,
copy location from 'file.csv' with delimiter E'\t' NULL as 'NULL' CSV;
ERROR: extra data after last expected column
CONTEXT: COPY location, line 1: "AD AD100 Canillo 42.5833 1.6667 6"
我的表描述是
Table "public.location"
Column | Type | Modifiers
-------------+------------------------+-----------
countrycode | character varying(2) |
postalcode | character varying(20) |
place | character varying(100) |
state | character varying(20) |
country | character varying(100) |
country2 | character varying(20) |
community | character varying(100) |
community2 | character varying(20) |
latitude | double precision |
longitude | double precision |
accuracy | integer |
如何解决这个问题?
输入:
AD AD100 Canillo 42.5833 1.6667 6
AD AD200 Encamp 42.5333 1.6333 6
AD AD300 Ordino 42.6 1.55 6
AD AD400 La Massana 42.5667 1.4833 6
AD AD500 Andorra la Vella 42.5 1.5 6
AD AD600 Sant Julià de Lòria 42.4667 1.5 6
AD AD700 Escaldes-Engordany 42.5 1.5667 6
AR 3636 "POZO CERCADO (EL CHORRO (F), DPTO. RIVADAVIA (S))" SALTA A -23.4933 -61.9267 3
AR 4123 LAS SALADAS SALTA A -25.7833 -64.5 4
AR 4126 LA MARAVILLA SALTA A -26.0833 -65.263 3
AR 4126 TALA SALTA A -26.1167 -65.2833 4
AR 4126 LA ASUNCION SALTA A -26.0833 -65.263 3
AR 4126 BRETE SALTA A -26.0667 -65.3667 4
AR 4126 EL SUNCHAL SALTA A -26.0833 -65.263 3
AR 4126 CEIBAL SALTA A -26.1 -65.0167 4
AR 4126 BARADERO SALTA A -26.0833 -65.263 3
AR 4126 CANDELARIA SALTA A -26.1 -65.1 4
AR 4126 ALEM SALTA A -26.0833 -65.263 3
AR 4126 EL BRETE SALTA A -26.0667 -65.3667 4
AR 4126 EL CUIBAL SALTA A -26.0833 -65.263 3
AR 4126 EL JARDIN SALTA A -26.0833 -65.3833 4
AR 4126 OVEJERO SALTA A -26.0833 -65.263 3
AR 4126 LOS MOGOTES SALTA A -26.0333 -65.2 4
AR 4126 "MIRAFLORES (TALA, DPTO. CANDELARIA)" SALTA A -26.0833 -65.263 3
这是一些例如输入...
当我在 ms xcel 工作表中打开此文件时,使用分隔符选项卡将数据正确分隔到相关列。
输入带有制表符和空值的文件,
AD\tAD100\tCanillo\t\n\t\n\t\n\t\n\t\n\t\n\t42.5833\t1.6667\t6
AD\tAD200\tEncamp\t\n\t\n\t\n\t\n\t\n\t\n\t42.5333\t1.6333\t6
AR\t3636\t"POZO CERCADO (EL CHORRO (F), DPTO. RIVADAVIA (S))"\tSALTA\tA\t\n\t\n\t\n\t\n\t-23.4933\t-61.9267\t3