Home > Mobile >  SQL Query Where array of objects
SQL Query Where array of objects

Time:01-08

I have a table that has a field that contains an array of objects. Here's a sample value of the field

[
   {a: "test"},
   {a: "testing"}
]

I'm trying to do a query data where the comparison is on the array of object fields that kinda looks like this SELECT * FROM table_1 WHERE table_1.a = "test". The part that I can't get is on the WHERE condition or is this not possible?

CodePudding user response:

I have found an answer to this

its either of this two

   SELECT * FROM table_1 WHERE table_1.field@>'[{"a":"test"}]'::jsonb

or

   SELECT * FROM table_1 WHERE table_1.field::text similar to '%("a": "test")%'
  • Related