1

I have an object with an array field, called emails

user.emails = ['[email protected]','[email protected]']

I want to find all the users from a list of emails:

emails_to_find = ['[email protected]','[email protected]']

I tried running

User.where(emails: emails_to_find)

but I get

ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR:  array value must start with "{" or dimension information

How do I do that? What the error means?

0

1 Answer 1

3

If the column is of type Array and in the migration that created it you have something like t.string 'emails', array: true, try using:

User.where("emails @> ARRAY[?]::varchar[]", ['[email protected]','[email protected]'])
User.where("'[email protected]' = ANY (emails)")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.