我正在尝试将Oracle 12c查询迁移到Postgres11.5。
这里是json:
{
"cost": [{
"spent": [{
"ID": "HR",
"spentamount": {
"amount": 2000.0,
"country": "US"
}
}]
}],
"time": [{
"spent": [{
"ID": "HR",
"spentamount": {
"amount": 308.91,
"country": "US"
}
}]
}]
}
这里是必须迁移到Postgres 11.5的查询:
select js.*
from P_P_J r,
json_table(r.P_D_J, '$.*[*]'
COLUMNS(NESTED PATH '$.spent[*]'
COLUMNS(
ID VARCHAR2(100 CHAR) PATH '$.ID',
amount NUMBER(10,4) PATH '$.spentamount.amount',
country VARCHAR2(100 CHAR) PATH '$.spentamount.country'))
) js
结果:
ID, amount, country
HR, 2000.0,US
HR,308.91,US
我在这里有两个问题:
$.*[*]
是什么意思?
我们如何在Postgres中迁移此查询,以使其直接查看'花费',而不是浏览'成本'->'花费'或'时间'->'花费'
] >>我正在尝试将Oracle 12c查询迁移到Postgres11.5。这是json:{“ cost”:[{“花”:[{“ ID”:“ HR”,“ spentamount”:{“ amount”:2000.0,“ country”:“ US” ...
Postgres中无法直接替换json_table。您将不得不组合多个调用来分解JSON结构。
您没有向我们显示您的预期输出,但是据我所知,以下应该做同样的事情: