PostgreSQL中比较阵列 [英] Comparing arrays in PostgreSQL

查看:126
本文介绍了PostgreSQL中比较阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图确定是否从值列表中的任何项目在PostgreSQL中数组列present。

I am attempting to determine if any item from a list of values is present in an array column in PostgreSQL.

SELECT * FROM data WHERE array IN (array)

我有这方面的工作使用和放大器;&安培;运算符和手动构造数组文本:

I have this working using the && operator and a manually constructed array literal:

SELECT id, data FROM things WHERE '{"value", "other"}' && (array_column) 

有没有实现这一点的一个更好的办法?

Is there a better way of accomplishing this?

推荐答案

这是一个相当不错的方式,你是什么更好的办法呢?

This is a quite good way, what do you mean by a better way?

有一件事情是可以做一些其他的方式,您可以使用创建数组 ARRAY [...] 是这样的:

There is one thing which could be done some other way, you can create the array using ARRAY[...] like this:

select ARRAY['a', 'b'] && '{"a", "c"}';

这篇关于PostgreSQL中比较阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆