1 回答

TA貢獻1801條經驗 獲得超16個贊
您IN在WHERE子句中使用運算符來檢查值是否與值列表中的任何值匹配。
IN需要一個明確的值列表(或子查詢)。
我為您的案例創建了一個示例場景,如下所示:
contributors := []int{20, 25, 27}
var tmp []string
for _, v := range contributors {
tmp = append(tmp, fmt.Sprint(v))
}
query := "SELECT * from table_name where contributors in (" + strings.Join(tmp, ",") + ")"
或者
ANY
適用于數組。如果數組中已有值列表,這將很有用。
使用ANY
運算符,您只能搜索一個值。
select * from table_name where value = ANY(contributors);
如果要搜索多個值,可以使用@>
運算符。
@>
是“包含”運算符。
為幾種數據類型定義如下:
數組:http ://www.postgresql.org/docs/current/static/functions-array.html
范圍類型:http ://www.postgresql.org/docs/current/static/functions-range.html
幾何類型:http ://www.postgresql.org/docs/current/static/functions-geometry.html
JSON(和 JSONB):http ://www.postgresql.org/docs/current/static/functions-json.html
- 1 回答
- 0 關注
- 152 瀏覽
添加回答
舉報