插入JSON列postgres [重复]

This question already has an answer here:

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"]

How can I enter this into a json column , what I am trying is this

 $this->db->query("
       INSERT INTO tag_sets (type, value) VALUES
            ('sorting_options', " 
            'Price Descending', 'Price Ascending', 'Name Ascending', 
            'Date Descending'";
      ");

This gives me an error, what is the correct way to insert into a json column?

</div>

Try this

$json = addslashes('"sorting_options",  "Price Descending", "Price Ascending", "Name Ascending", "Date Descending"');

$this->db->query("INSERT INTO tag_sets (type, value) VALUES ('sorting_options', '{$json}')");

PostgreSQL cannot cast a string into json. You must adjustment a JSON syntax before execute you query.

$this->db->query("
       INSERT INTO tag_sets (type, value) VALUES
            ('sorting_options', " 
            '[\"Price Descending\", \"Price Ascending\", \"Name Ascending\", \"Date Descending\"]'";
      ");

Try to execute it.