【问题标题】:postgres update key inside jsonb fieldjsonb字段内的postgres更新键
【发布时间】:2021-01-30 20:53:09
【问题描述】:

我正在使用 Postgres 数据库和 laravel 框架 我有 jsonb 字段包含:

{
    "patientInfo": {
        "id": 1612038632,
        "gender": "female",
        "lastName": "تست",
        "firstName": "تست",
        "phoneNumber": "9399999999"
    },
    "cancelInfo": {
        "channel":"Assistant"
    }
}

如何编写查询以仅更新患者信息并保持其他键不变? 表名是约会请求,字段名是详细信息。 我写了这个查询,但它需要修复:

AppointmentRequest::where('registerar_id', Auth::guard('PATIENT')->user()->account_id)
                    ->whereRaw(" \"detail->patientInfo\" @> '{\"id\": \"$request->otherPatientId\"}'")
                    ->update(['detail' => ['patientInfo' => json_encode($data)]]);

【问题讨论】:

    标签: php laravel postgresql


    【解决方案1】:

    您是否尝试过类似the documentation 中的示例?

    也许->update(['detail->patientInfo' => json_encode($data)])

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-06
      • 2021-03-16
      • 1970-01-01
      • 2023-01-29
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多