問題:
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