【问题标题】:updating jsonb field in postgresql更新 postgresql 中的 jsonb 字段
【发布时间】:2021-02-12 10:29:14
【问题描述】:

我正在尝试更新 postgresql 中 jsonb 列中的值。

// column 'settings'
{
  "country": "us",
  "language": "en"
}

我想使用准备好的语句并且我想更新一个特定的值,所以不是整个 jsonb 对象。

这不起作用:

UPDATE users SET settings = jsonb_set(settings, '{country}', '$1'::jsonb)

我正在尝试将准备好的语句的值转换为 jsonb,它不起作用。错误是invalid input syntax for type json

更新 jsonb 字段中特定值的正确方法是什么。

我正在使用 nodejs pg。

【问题讨论】:

    标签: sql node.js json postgresql sql-update


    【解决方案1】:

    我认为以下语法应该在准备好的语句中起作用

    UPDATE users SET settings = jsonb_set(settings, '{country}', to_jsonb($1::text))
    

    【讨论】:

      猜你喜欢
      • 2015-07-16
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 2021-06-07
      • 2015-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多