ruby续集gem-如何使用pg_array扩展名查询数组 [英] ruby sequel gem - how to query arrays with the pg_array extension

查看:81
本文介绍了ruby续集gem-如何使用pg_array扩展名查询数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 pg_array 扩展名和续集版本4.1.1。

I am using the pg_array extension and sequel version 4.1.1.

我添加了以下扩展名:

Sequel::Database.extension :pg_array

我创建了一个像这样的列: / p>

I have created a column like this:

alter_table :emails do
  add_column :references, "text[]", null: true
end

我可以将数组加载和检索到postgress数组列中,就像使用普通数组一样。

I can load and retrieve arrays into a postgress array column, just like working with normal arrays.

从上面的链接尚不清楚的是如何根据此数组列中的值执行查询。

What is not clear from the above link is how do I execute a query based on the values in this array column.

例如,如果电子邮件表中的一行在引用列中包含以下值:

For example, if one row in the emails table contained these values in the references column:

                             references                             
--------------------------------------------------------------------
 {}
 {5363f773bccf9_32123fe75c45e6f090953@Pauls-MacBook-Pro.local.mail}

如何查询电子邮件表以查找包含上述值的引用数组值的行:

How can I query the emails table to find a row that contains a references array value of the above value:

Email.where(references: ????)


推荐答案

使用 pg_array_ops 扩展名:

Sequel.extension :pg_array_ops
Email.where(Sequel.pg_array_op(:references).contains('5363f773bccf9_32123fe75c45e6f090953@Pauls-MacBook-Pro.local.mail'))

这篇关于ruby续集gem-如何使用pg_array扩展名查询数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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