2021年3月29日星期一

How to filter based on postgres ARRAY type length in sqlalchemy?

I'm trying to filter the db to get result based on the array column's length. In specific I need to get results which are of length <= given value.

For Example:

| COLNAME     |  | {1}         |  | {3,20,3400} |  | {1,4,7}     |  | {3,3279}    |  | {1,4}       |  | {3}         |  | {1,4,54}    |  | {3,44}      |  

And I need to get let's say length <= 2 and expected result would be:

| COLNAME  |  | {1}      |  | {3,3279} |  | {1,4}    |  | {3}      |  | {3,44}   |  

I'm new to this, so I'm not able to find it on my own properly. array_agg and array_length functions are there which might help, I'm looking into how to use it properly, but if someone just knows that will be a big help.

https://stackoverflow.com/questions/66864556/how-to-filter-based-on-postgres-array-type-length-in-sqlalchemy March 30, 2021 at 11:53AM

没有评论:

发表评论