order by JSON data type postgres

后端 未结 3 1080
甜味超标
甜味超标 2021-02-03 23:07

I have a Postgres table which has column of type JSON which has a bunch of JSON objects in them. I want to query the table records and order the results by a value stored in the

3条回答
  •  我寻月下人不归
    2021-02-03 23:50

    You put asc in the fieldname. There's no key named value asc in the json, so data ->> 'value asc' will always return NULL.

    You actually want:

    select * from table ORDER BY data->>'value' ASC 
    

    to match the json, possibly even:

    select * 
    from table 
    WHERE data ->> 'name' = 'stuff'
    ORDER BY data->>'value' ASC 
    

提交回复
热议问题