鑑於此查詢: -的Postgres 9.3 JSON輸出多維對象
SELECT id as id,
attributes->>'name' as file_name,
status
from workflow.events
where schema='customer'
and type='FILE_UPLOAD'
id,file_name, status
1,name,status
2,name2,status2
我要輸出這樣的結構: -
{
"1" :{"id" :"1", "file_name" : "name", "status" : "status1"},
"2" :{"id" :"2", "file_name" : "name2","status" : "status2"}
}
我可以用字符串函數在此刻做,但這個似乎凌亂和低效。 CAn它使用本地postgresql json函數完成?
可能重複http://stackoverflow.com/ questions/11198625/json-output-in-postgresql) – 2013-10-15 11:11:14
有幾個有用的json函數,即row_to_json(),它應該派上用場:http://www.postgresql.org/docs/current/static/functions -json.html –