【发布时间】:2023-02-04 20:37:00
【问题描述】:
我有与this one 类似的问题(最相似的是&& 的答案)。对于 postgres,我想得到数组列和 python 列表的交集。我试着用 && 操作员来做到这一点:
query(Table.array_column.op('&&')(cast(['a', 'b'], ARRAY(Unicode)))).filter(Table.array_column.op('&&')(cast(['a', 'b'], ARRAY(Unicode))))
但似乎 op('&&') 返回 bool 类型(对过滤器有意义)而不是交集。
所以对于表数据:
id | array_column
1 {'7', 'xyz', 'a'}
2 {'b', 'c', 'd'}
3 {'x', 'y', 'ab'}
4 {'ab', 'ba', ''}
5 {'a', 'b', 'ab'}
我想得到:
id | array_column
1 {'a'}
2 {'b'}
5 {'a', 'b'}
【问题讨论】:
标签: python postgresql sqlalchemy