我正在嘗試過濾掉一個特定欄位中包含帶有單詞的特殊字符的記錄。
例如:
-[ RECORD 1 ]-------------- ------------------------------
id | 3151
description | Manual add from SCCM
mac_address | d4258be8d064
status | Unknown
mac_vendor | Intel Corporate
added_by | Policy Manager
added_at | 2019-02-19 14:29:21.802413 00
updated_at | 2022-10-19 10:57:15.960282 00
attributes | {"Our Device": "true"}
extras |
org_id | 1
permit_id | 1
agentless_managed_endpoint | 0
我試過了
select *
from tips_endpoints
where description = 'Manual add from SCCM'
AND attributes = '{"Our Device": "true"}';
但它失敗了。
我需要能夠找到屬性值 = {"Our Device": "true"} 的記錄
uj5u.com熱心網友回復:
嘗試這個:
select *
from tips_endpoints
where description = 'Manual add from SCCM'
AND attributes Like '%{"Our Device": "true"}%';
UPD,對于 Postgres:
select *
from tips_endpoints
where description = 'Manual add from SCCM'
AND attributes::text Like '%{"Our Device": "true"}%';
uj5u.com熱心網友回復:
由于該列是一jsonb列,因此更好的方法是使用其中一個JSON 函式
and attributes ->> 'Our Device' = 'true'
或者
and attributes @> {"Our Device": "true"}
如果需要,兩個運算式都可以被索引。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/519442.html
標籤:PostgreSQL
上一篇:如何選擇最小日期而不是最大日期
