標籤:and span html code post data 方案 where select
前台: dhtmlxgrid.顯示資料
其格式為:
{
rows:[
{id:1,data:[1,2,3]}
,{}
]
}
如果在postgesql裡直接產生這樣的串呢??
這是就今天要做的事.
也是測試了一天,還是別人的協助下完成:
1,2 本人自己寫的,怎麼也達不成這個目標:
3, 群友給的方案:完美解決
--方案1: select json_agg(row_to_json(t))::text from (select id,concat_ws(‘,‘,pt_name,pt_description) as mydata from project_template )as t;--結果[{"id":1,"myData":"whq,admin"},{"id":2,"myData":"eathon,sys"}] --不理想--方案2:select json_agg(row_to_json(t))::text from (select id,‘[‘|| concat_ws(‘,‘,pt_name,pt_description) ||‘]‘ as mydata from project_template ) as t--結果[{"id":1,"myData":["whq,admin"]},{"id":2,"myData":["eathon,sys"]}]好像對了,可是仔細看:"myData":["eathon,sys"] 不對,應該是:"myData":["eathon","sys"]--方案3:select json_agg(row_to_json(t))::text from (select id,array[pt_name,pt_description] as mydata from project_template where 1=1 and id=1) as t--結果:[{"id":1,"myData":["whq","admin"]},{"id":2,"myData":["eathon","sys"]}]
postgresql 直接產生 dhtmlxgrid 可以接受的JSON串