PostgreSQL directly generates a JSON string that Dhtmlxgrid can accept

Source: Internet
Author: User
Tags postgresql

Front desk: Dhtmlxgrid. Displaying data

The format is:

{
rows:[
     {id:1,data:[1,2,3]}
,{}
]
}

What if you generate such a string directly in the Postgesql?

That's what we're going to do today.

It was also tested one day, or someone else's help was done:

I write myself, how can not achieve this goal:

3, group friends to the solution: the Perfect solution

--Scenario 1:Select Json_agg (Row_to_json (t))::TextFrom (Select Id,concat_ws (‘,', pt_name,pt_description)As MyDataFrom Project_template)AsT--result [{"id": 1, "MyData": "Whq,admin"},{"id": 2, "MyData": "Eathon,sys"}]--Not ideal--Scenario 2:Select Json_agg (Row_to_json (t))::TextFrom (Select ID,‘[‘|| Concat_ws (‘,', pt_name,pt_description)||‘]‘As MyDataFrom Project_template)AsT--result [{"id": 1, "MyData": ["Whq,admin"]},{"id": 2, "MyData": ["Eathon,sys"]}] it seems right, but look closely: "MyData":["Eathon,sys"]No, it should be: "MyData":["Eathon", "SYS"]--Scenario 3:Select Json_agg (Row_to_json (t))::TextFrom (Select Id,array[pt_name,pt_descriptionas mydata from project_template where =1 and id= as  t--result: [{"id": 1, " MyData ": [" WHQ "," admin "]},{" id ":  2, "MyData": [ "Eathon", "SYS"             /span>       

PostgreSQL directly generates a JSON string that Dhtmlxgrid can accept

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.