Ruby sequel gem - how to request arrays with pg_array extension

I use the pg_array extension and the continuation of version 4.1.1.

I added the extension as follows:

Sequel::Database.extension :pg_array

I created a column like this:

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

I can load and retrieve arrays into columns of a postgress array, just like working with regular arrays.

From the link above it is not clear how to execute the query based on the values ​​in this column of the array.

For example, if one row in the email table contained these values ​​in the link column:

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

How can I query the email table to find a string containing the value of an array of links of the specified value:

Email.where(references: ????)
+4
source share
2 answers

pg_array_ops:

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

?

ref = '5363f773bccf9'
emails = Email.arel_table
Email.where( emails[ :references ].matches( "%#{ref}%" ))
0

Source: https://habr.com/ru/post/1539053/


All Articles