我有带ID
s: 的DB 1 2 3 4 5
。我需要返回数组中存在的元素(通常在 中指定的简单数据列表IN ( ... )
),但不要在数据库中退出。例如检查值:1, 2, 3, 4, 5, 6, 7
.
所以查询应该返回6, 7
. 我怎样才能用 PostgreSQL 做到这一点?
这可以解决使用 except
select *
from unnest(array[1,2,3,4,5,6]) as t(id)
except
select id
from the_table
附上一些测试数据:
select *
from unnest(array[1,2,3,4,5,6]) as t(id)
except
select id
from (values (1), (2), (3), (4) ) as the_table(id)
返回
id
--
5
6
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句