Postgres JSON selecting a row by list

137 Views Asked by At

I have a table that has a JSON list as one of its values. The column name is list_order and the value would be something like: [1,2,3].

I am having trouble doing a WHERE comparison to select by list_order. In pure SQL, it would be: SELECT * FROM table_name list_order=[1,2,3];

The closest example I found was this: How do I query using fields inside the new PostgreSQL JSON datatype?. However, this grabs the value of a key in the JSON where the JSON is a dictionary and not a list. I've tried modifying it to suit my need but it did not work.

Any suggestions? Is that even possible? Why is not documented? Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

I found the answer. I need to compare it as text:

"SELECT * FROM table WHERE list_order::text='[1,2,3]';