【发布时间】:2020-09-28 11:07:35
【问题描述】:
是否可以使用 Eloquent ORM 运行这个 postgres 查询?
select * from "table" where "column"->'key' ? '1'
在查询中使用? 会引发错误。有没有替代方法?
【问题讨论】:
标签: laravel postgresql eloquent orm
是否可以使用 Eloquent ORM 运行这个 postgres 查询?
select * from "table" where "column"->'key' ? '1'
在查询中使用? 会引发错误。有没有替代方法?
【问题讨论】:
标签: laravel postgresql eloquent orm
改用原始查询:
DB::raw(" select * from \"table\" where \"column\"->'key' ? '1' ");
【讨论】:
dd( exception here ) 更好地诊断它
您可以使用jsonb_exists 函数。所有问号都确定为准备好的语句的占位符。
或者在 php 7.4 中,您可以使用 ??(在此处回答:How to use Postgres jsonb '?' operator in Laravel with index support?)
【讨论】: