Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

How do I get all the empty records for a jsonb column with Active Record ?

share|improve this question
    
Are you looking for all rows where the jsonb column is null? Or, are you looking for all rows where the jsonb column is an empty object '{}'? Some example code/sql would help here. – MrWillihog Jun 8 at 14:24
    
I am looking for all the rows where the jsonb column is an empty object '{}' . I actually tried Active Record query interface Model.where.not(my_column: {}) – Shani Jun 9 at 9:56
    
Have you tried Model.where("my_column = '{}'") – MrWillihog Jun 9 at 10:12
    
Thanks that works – Shani Jun 9 at 10:54
    
I'll add it as an answer then. – MrWillihog Jun 9 at 11:02
up vote 1 down vote accepted

You can query for empty objects in a JSONB column using the following syntax:

Model.where("column = '{}'")
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.