1

I have a record that looks like this: { properties: [1,2] }

I want to search to find the field where the properties match exactly.

Record.where("(query)")

So far I tried things I found from this answer including

"properties#>>'{array,0}' = '1'"

to try to get the first element of an array to match.

I just don't understand the query interface for postgres columns at all. Can someone help me out? How do I search for an array with contents I know I want to match exactly?

RandallB
  • 5,415
  • 6
  • 34
  • 47

1 Answers1

1

To access elements of an array, use their numeric index with the format fieldname->>index

So the answer to the original query is:

properties ->>0 is '1' and properties->>1 is '2'
RandallB
  • 5,415
  • 6
  • 34
  • 47