[英]Filter integer array of jsonb column in postgres using EF Core and NpgSql
我想根據 json 整數數組過濾行,例如,我的表看起來像這樣
| Id | Name | TypeJson |
| --- | ---------- | -------- |
| 1 | Name One | [1,2] |
| 2 | Name Two | [2,3] |
| 3 | Name Three | [4,7] |
其中 Id 是 int 類型,Name - text 和 TypeJson - jsonb。
我正在嘗試通過以下查詢來過濾行
await _dbContect.Table
.Where(x => !string.IsNullOrEmpty(x.TypeJson) &&
EF.Functions.JsonExistAny(x.TypeJson, "2")
.ToListAsync();
結果我希望得到 1 行和 2 行,但出現意外錯誤
Npgsql.PostgresException (0x80004005): 42883: function btrim(jsonb, unknown) does not exist
...
Exception data:
Severity: ERROR
SqlState: 42883
MessageText: function btrim(jsonb, unknown) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Position: 593
File: parse_func.c
Line: 528
Routine: ParseFuncOrColumn
我應該以某種特定格式傳遞"2"
還是拋出的異常是什么?
在 npgsql github 上發布了這個問題,正如預期的那樣,這是我這邊的問題,因為該列是 jsonb 類型的字符串函數,如IsNullOrEmpty()
和IsNullOrWhiteSpace()
不能應用於它,而且它甚至不需要,因為 EF json 函數將無論如何將 null 值過濾為 false。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.