我有一个CVS文件,其中包含表示十六进制int的coma separeted字符串值。这是一个抽样file.csv
7c8e507319bd11219373301ad75fdda8,7586a0c46c6a288f620278c727ae699b,493ab373681cac5f1ea1bf3cd69390fc
00376951c73ab83a673184af6886939f,7586a0c46c6a288f620278c727ae699b,cb3e56042f3385fd68bb682973d529c8
fe4a00d3207bcd6f68e7c9092a7e6bee,7586a0c46c6a288f620278c727ae699b,3c45806c8b3b0b25086c0492d7077d83
be0d0b358d102c10c63332d6dba84c6b,7586a0c46c6a288f620278c727ae699b,5852d834b037be87d31a87c90f3ecdf2
90476f4583fa156e99f43480d2aaeefa,7586a0c46c6a288f620278c727ae699b,5852d834b037be87d31a87c90f3ecdf2
e7cf69f2eabcc56e789378f7c2bb97c5,7586a0c46c6a288f620278c727ae699b,5852d834b037be87d31a87c90f3ecdf2
85d714a1cb30b77f7bd9fe7d08f76a39,7586a0c46c6a288f620278c727ae699b,5852d834b037be87d31a87c90f3ecdf2
e67475d8af00b28d1dc7e2019252a1ad,7586a0c46c6a288f620278c727ae699b,ab752539fe24e0f510f1f4771f214c54
8cbe258b1dd9de63aaf3fd050e86747c,7586a0c46c6a288f620278c727ae699b,3c45806c8b3b0b25086c0492d7077d83
d838591510647bbd9a02c5b6fef7d0fc,7586a0c46c6a288f620278c727ae699b,3c45806c8b3b0b25086c0492d7077d83
4e03c3c98bde65b2c1c1762681f691e1,7586a0c46c6a288f620278c727ae699b,3c45806c8b3b0b25086c0492d7077d83
9e3022eac89f3b708331db61b2804d92,7586a0c46c6a288f620278c727ae699b,3c45806c8b3b0b25086c0492d7077d83
c744553021baa07a1b7ee512a5c0fb89,7586a0c46c6a288f620278c727ae699b,3c45806c8b3b0b25086c0492d7077d83
由于文件可能很大(2 GB),我想使用postgresql COPY
命令在表中导入它们。这是表模式
CREATE TABLE IF NOT EXISTS "datas" (
s BYTEA,
p BYTEA,
o BYTEA, PRIMARY KEY (s,o)
)
我需要在此COPY
查询中修复哪些内容才能完成此任务? ?
COPY datas FROM 'file.csv' (DELIMITER(','));
版
我也对MySQL
解决方案提案
答案 0 :(得分:2)
靠近您输入的COPY
postgreSQL格式包含以bytea
\\x
列
示例:
COPY (select 'abc'::bytea) TO stdout;
将输出:
\\x616263
相反,它可以将带有COPY FROM
的字符串导入到bytea字段中。
假设命令行环境为awk
,输入可以动态转换为此格式并流式传输到psql
:
awk -F, '{print "\\\\x"$1",\\\\x"$2",\\\\x"$3}' file.csv | psql -c "COPY datas FROM stdin delimiter ','"
答案 1 :(得分:0)
如果我指定格式,它适用于我:
copy datas from 'file.csv' csv;
select * from datas;
s | p | o
--------------------------------------------------------------------+--------------------------------------------------------------------+--------------------------------------------------------------------
\x3763386535303733313962643131323139333733333031616437356664646138 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3439336162333733363831636163356631656131626633636436393339306663
\x3030333736393531633733616238336136373331383461663638383639333966 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x6362336535363034326633333835666436386262363832393733643532396338
\x6665346130306433323037626364366636386537633930393261376536626565 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3363343538303663386233623062323530383663303439326437303737643833
\x6265306430623335386431303263313063363333333264366462613834633662 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3538353264383334623033376265383764333161383763393066336563646632
\x3930343736663435383366613135366539396634333438306432616165656661 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3538353264383334623033376265383764333161383763393066336563646632
\x6537636636396632656162636335366537383933373866376332626239376335 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3538353264383334623033376265383764333161383763393066336563646632
\x3835643731346131636233306237376637626439666537643038663736613339 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3538353264383334623033376265383764333161383763393066336563646632
\x6536373437356438616630306232386431646337653230313932353261316164 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x6162373532353339666532346530663531306631663437373166323134633534
\x3863626532353862316464396465363361616633666430353065383637343763 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3363343538303663386233623062323530383663303439326437303737643833
\x6438333835393135313036343762626439613032633562366665663764306663 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3363343538303663386233623062323530383663303439326437303737643833
\x3465303363336339386264653635623263316331373632363831663639316531 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3363343538303663386233623062323530383663303439326437303737643833
\x3965333032326561633839663362373038333331646236316232383034643932 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3363343538303663386233623062323530383663303439326437303737643833
\x6337343435353330323162616130376131623765653531326135633066623839 | \x3735383661306334366336613238386636323032373863373237616536393962 | \x3363343538303663386233623062323530383663303439326437303737643833
(13 rows)