【发布时间】:2021-03-31 18:38:49
【问题描述】:
我在 Postgres 上有表 my_table 和 id,name (varchar), properties (jsonb) 字段。
name 字段已经插入,现在我想在属性字段中添加一些数据。
<?php
global $dbh;
$queryUpdate = "UPDATE my_table set
properties=jsonb_set(coalesce(properties,'{}'),'{token_approval}','{$token}',true) where id=:id";
$stmt = $dbh->prepare($queryUpdate);
$stmt->bindValue(':id', $idPengajuanUtama);
try {
$stmt->execute();
} catch (PDOException $e) {
throw new RuntimeException($e->getMessage() . "\r\n Function " . __METHOD__);
return false;
}
return true;
?>
当我运行代码时,我总是收到以下错误。
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type json\nLINE 1: ..._set(coalesce(properties,'{}'),'{token_approval}','asdfadsna...\n
我该如何解决这个问题?
提前致谢。
【问题讨论】:
标签: php json postgresql pdo sql-update