Fran Martinez
Fran Martinez

Reputation: 3052

ActiveRecord: How to find Postgres rows with empty array?

I have a model created with this migration:

create table :some_table do |t|
  t.string :list, array: true, default: []
end

I would like to find the record whose "list" array is empty. I tried with this:

SomeTable.where(list: [])

but it returns nil and I have records with the list emtpy.

Upvotes: 0

Views: 31

Answers (1)

Pardeep Dhingra
Pardeep Dhingra

Reputation: 3946

Try:

SomeTable.where(list: '{}')

Reference list datatype

Upvotes: 1

Related Questions