我一直在使用pgfutter将JSON文件导入postgresql。
现在我正在尝试将该json文件解析为我的psql表。这是我的表:
CREATE TABLE organisation (
id int8 PRIMARY KEY NOT NULL,
department VARCHAR(255),
business_type VARCHAR(255),
unit_active INTEGER
);
这是我的json的一个例子:
{
"extension":[
{
"name":"unitActive",
"value":"Active"
},
{
"name" : "businessType",
"value" : "Other"
},
{
"name":"specialities",
"value":[
{
"value":"allm kirurgi"
},
{
"value":"neurologi"
},
{
"value":"ortopedisk kirurgi"
}]
}],
"catalog":"main",
"department":"hospital"
}
我一直在看postgresql documentation,但我不太清楚如何规范化对象,在本例中是我的JSON中的扩展对象。
这就是我得到的
INSERT INTO organisation
SELECT nextval('organisationsSequence'),
data->>'department' as department,
"Something here" as business_type,
"Something here" as unit_active
FROM import.collection WHERE data->>'catalog' = 'main';
所以我想要实现的是“选择extension.value,其中extension.name = businessType”