鉴于此查询: -的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 –