当前位置:Gxlcms > 数据库问题 > postgresql 直接生成 dhtmlxgrid 可以接受的JSON串

postgresql 直接生成 dhtmlxgrid 可以接受的JSON串

时间:2021-07-01 10:21:17 帮助过:4人阅读

这是就今天要做的事.

也是测试了一天,还是别人的帮助下完成:

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串

标签:and   span   html   code   post   data   方案   where   select   

人气教程排行