1
我正在使用內部連接來連接3個表,所有者,存儲和計算機。 我試圖從多個表中查看輸出JSON是這樣的:格式JSON Postgresql
SELECT ow.*, st.*, ma.*
FROM owner ow
INNER JOIN st.store ON ow.OwnerId = st.OwnerId
INNER JOIN machine ma ON ma.StoreId = st.StoreId;
我想JSON格式是這樣的:
{
"OwnerId": "1d2dd",
"Name": "name test",
"Store":[{
"StoreId": "s3ss5",
"Name": "Store1",
"Code": "bla",
"Machine":[{
"MachineId": "axpeo",
"Name": "Machine1",
"Type": "type1"
}]
},
{
"StoreId": "ddf22",
"Name": "Store2",
"Code": "ble",
"Machine":[{
"MachineId": "weds",
"Name": "Machine2",
"Type": "type2"
},
{
"MachineId": "axdso",
"Name": "Machine3",
"Type": "type3"
}]
}]
}
但JSON沒有格式化,這樣 返回我使用PostgreSQL的。
? –
普通的SQL select語句永遠不會返回JSON,請查看Postgres中可用的JSON函數:https://www.postgresql.org/docs/current/static/functions-json.html –