dongqing314511 2018-02-26 18:22
浏览 85
已采纳

插入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>
  • 写回答

2条回答 默认 最新

  • dougaopu7938 2018-02-26 22:40
    关注

    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}')");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:需要 MATLAB 运行程序,对比四个多址通信方式(TDMA,FDMA,CDMA,OFDMA)的抗噪声性能
  • ¥15 有没有复现过PFENet的,如何解决?
  • ¥15 FDMA,OFDMA,TDMA 和 CDMA 系统容量对比仿真
  • ¥15 图神经网络的入侵检测
  • ¥15 工业数据采集技术+存储架构推荐
  • ¥15 GPT-SOVITS如何训练少数民族语言支持合成语音
  • ¥20 树莓派4b使用Camera Module 3时出现the system should be configured for the legacy camera stack问题
  • ¥200 GitHub开源程序配置在VScode调试
  • ¥15 爬虫保存的scv文件0kb
  • ¥20 如何实现基于强化学习的带电作业机械臂的运动规划与控制