1

I want to get all books that have nil empty string or empty hash on a property

Book.where(references: [nil, "", {}])

This gives me an error.

ERROR: invalid input syntax for type json LINE 1: ...on_id" = $1 AND ("books"."references" IN ('', '{}') ... ^ DETAIL: The input string ended unexpectedly. CONTEXT: JSON data, line 1:

references is a json field on a postgres database

Petran
  • 7,677
  • 22
  • 65
  • 104

1 Answers1

2

I have found here How to query a json column for empty objects?

Book.where(references: [nil, ""]).where("references::text = '{}'::text")
Jose Manuel
  • 183
  • 7
Petran
  • 7,677
  • 22
  • 65
  • 104