檢查 Postgres 數組中是否存在值 - Check if value exists in Postgres array

問題:

Using Postgres 9.0, I need a way to test if a value exists in a given array.使用 Postgres 9.0,我需要一種方法來測試給定數組中是否存在某個值。 So far I came up with something like this:到目前爲止,我想出了這樣的事情:

select '{1,2,3}'::int[] @> (ARRAY[]::int[] || value_variable::int)

But I keep thinking there should be a simpler way to this, I just can't see it.但我一直認爲應該有一個更簡單的方法,我只是看不到它。 This seems better:這似乎更好:

select '{1,2,3}'::int[] @> ARRAY[value_variable::int]

I believe it will suffice.我相信這就足夠了。 But if you have other ways to do it, please share!但是,如果您有其他方法可以做到這一點,請分享!


解決方案:

參考一: https://stackoom.com/question/l7pw
參考二: Check if value exists in Postgres array
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章