【问题标题】:Eloquent ORM does not allow ? operator used in JSONB lookup雄辩的 ORM 不允许? JSONB 查找中使用的运算符
【发布时间】:2020-09-28 11:07:35
【问题描述】:

是否可以使用 Eloquent ORM 运行这个 postgres 查询?

select * from "table" where "column"->'key' ? '1'

在查询中使用? 会引发错误。有没有替代方法?

【问题讨论】:

    标签: laravel postgresql eloquent orm


    【解决方案1】:

    改用原始查询:

    DB::raw(" select * from \"table\" where \"column\"->'key' ? '1' ");
    

    【讨论】:

    • 报错,不能用?在使用 ORM 的任何类型的查询中。
    • 我知道 Eloquent 支持 postgresql。确切的错误日志是什么?使用dd( exception here ) 更好地诊断它
    【解决方案2】:

    您可以使用jsonb_exists 函数。所有问号都确定为准备好的语句的占位符。

    或者在 php 7.4 中,您可以使用 ??(在此处回答:How to use Postgres jsonb '?' operator in Laravel with index support?

    【讨论】:

      猜你喜欢
      • 2013-08-19
      • 1970-01-01
      • 1970-01-01
      • 2015-01-15
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-22
      相关资源
      最近更新 更多