我正在尝试将json文件导入PostgreSQL。 示例数据:
{
"asin":"2094869245",
"title":"5 LED Bicycle Rear Tail Red Bike Torch Laser Beam Lamp Light",
"price":8.26,
"imhUrl":"http://ecx.images-amazon.com/images/I/51RtwnJwtBL._SY300_.jpg"
}
{
"asin":"7245456259",
"title":"Black Mountain Products Single Resistance Band - Door Anchor,
"price":10.49,
"imhUrl":"http://ecx.images-amazon.com/images/I/411Ikpf122L._SY300_.jpg"
}`
希望结果看起来像这样
data
--------------------------------------------------------------------
{
"asin":"2094869245",
"title":"5 LED Bicycle Rear Tail Red Bike Torch Laser Beam Lamp Light",
"price":8.26,
"imhUrl":"http://ecx.images-amazon.com/images/I/51RtwnJwtBL._SY300_.jpg"
}
--------------------------------------------------------------------
{
"asin":"7245456259",
"title":"Black Mountain Products Single Resistance Band - Door Anchor,
"price":10.49,
"imhUrl":"http://ecx.images-amazon.com/images/I/411Ikpf122L._SY300_.jpg"
}
数据为json类型。
我的JSON FILE将存储在一个名为data的JSON列中。
答案 0 :(得分:1)
如果您这样删除JSON文件中的换行符:
{ "asin":"2094869245", "title":"5 LED Bicycle Rear Tail Red Bike Torch Laser Beam Lamp Light","price":8.26, "imhUrl":"http://ecx.images-amazon.com/images/I/51RtwnJwtBL._SY300_.jpg"}
{ "asin":"7245456259", "title":"Black Mountain Products Single Resistance Band - Door Anchor", "price":10.49, "imhUrl":"http://ecx.images-amazon.com/images/I/411Ikpf122L._SY300_.jpg" }
您可以使用复制命令将其加载到表中:
create table js (a json);
copy js from '/tmp/data.json' DELIMITER '^' CSV QUOTE '''' ESCAPE '\'