Inserting an entry to JSON column in postgres

前端 未结 1 1407
挽巷
挽巷 2021-01-29 14:28

I have a JSON entry like this, which I need to enter into a column (called values)

[\"Price Descending\",\"Price Ascending\",\"Name Ascending\",\"Date Descending         


        
1条回答
  •  [愿得一人]
    2021-01-29 14:45

    If value is a json column, you can convert the text representation of the array directly.

    INSERT INTO tag_sets (type, value)
    VALUES (
      'sorting_options',
      '["Price Descending","Price Ascending","Name Ascending","Date Descending"]'::json
    );
    

    You could also use a method to generate an array, depending on your situation. Something like json_build_array.
    More json methods can be found here.

    0 讨论(0)
提交回复
热议问题