首页 > 解决方案 > 将列与postgressql中的文本数组进行比较

问题描述

我们有一个 PostgreSQL 数据库,其中我有两个列 text[] 数据类型的表。当我使用内部联接获取详细信息时,我看不到它与任何行匹配。例如

create table test{
names text[],
id
}

create table test_b{
names text[],
id
}

现在当我在查询下运行时,

SELECT t.* from test t inner join test_b tt 

其中 t.names=tt.names; 我没有看到任何结果。我什至尝试过正常查询

SELECT * FROM test where names='{/test/test}';

它也没有工作。有什么建议么?

标签: databasepostgresql

解决方案


我怀疑你想要数组重叠运算符&&。此外,由于您不需要从 中返回任何内容test_b,因此与相关子查询一起使用exists比 a 更相关join

select t.* 
from test t 
where exists (select 1 from test_b b where t.names && b.names)

推荐阅读