Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord: Find where column is nil or empty array

I have an array column in postgres and I want to find all the records where this column is either nil or []. I can search one or the other fine but trying both fails.

This is what I attempted

Model.where(column: [nil, []])

But I get the error

ActiveRecord::StatementInvalid (PG::InvalidTextRepresentation: ERROR:  malformed array literal: "{NULL,{}}")
DETAIL:  Unexpected "{" character.
like image 579
Qwertie Avatar asked Jul 14 '26 06:07

Qwertie


1 Answers

This worked for me

Model.where('column IS NULL OR column = ?', '{}')
like image 155
Qwertie Avatar answered Jul 15 '26 22:07

Qwertie