php - json_array 中的 Doctrine 搜索

标签 php json postgresql symfony doctrine

<分区>

我正在尝试在 Doctrine+Symfony 3 中的 json 类型中进行基本搜索。我的字段声明如下:

 /**
 * @ORM\Column(name="data", type="json_array", nullable=true)
 */
 private $data;

这是我存储库中在 MySQL 上运行良好的代码:

public function searchByKeyword($kw)
{
    $kw = str_replace(" ","%",$kw);
    return $this->createQueryBuilder("d")
        ->join("d.product", "p")
        ->where("d.data like :search")
        ->setFirstResult(0)
        ->setMaxResults(50)
        ->orderBy("p.createdOn", "DESC")
        ->setParameter("search", "%" . $kw . "%")->getQuery()->execute();
}

我转向可以处理 JSON 类型并且不对 json 数组使用 TEXT 的 Postgresql 9.5。我有这个错误:

SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: json ~~ unknown

我很确定我应该将 json 字段转换为文本来解决我的问题,但我尝试了 (d.data::TEXTd.data::TEXT 但它不起作用。

最佳答案

There is no equality (or inequality) operator for the data type json as a whole, because equality is hard to establish. You will love jsonb in Postgres 9.4, where this is possible. More details in this related answer on dba.SE (last chapter)

在这里看到:https://stackoverflow.com/a/24296054/652318

这里还有一些相关的东西: https://stackoverflow.com/a/32843380/652318

您可能必须创建一个新类型来将其转码以使用::表示法。

关于php - json_array 中的 Doctrine 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47388433/

相关文章:

php - 如何在 SQL 中管理产品选项和仓库项目之间的关系

php - 如何杀死Windows后台运行的特定cmd.exe进程?

php - 在本地 xampp/apache 服务器上设置 SSL

php - 使用 Jquery Ajax 从 Mysql 中检索数据

c# - 如何使用 C# 创建 Google DataTable JSON 预期源?

json - 微软团队 : "Something went wrong" while installing my custom app into my organization's team

json - 如何使用 flutter 更新 json 数据

ruby-on-rails - PGconn.connect ....断开连接在哪里?

postgresql - 如何停止/终止 postgresql 中的查询?

node.js - use_env_variable 在 sequelize 中返回 undefined