我尝试查询用户ID列表。我正在使用Go Pq库。
func ListUsers(userIDs []interface{}) (users []User, err error) {
stm := `SELECT
U.id,
(
CASE WHEN TRIM(UP.first_name || ' ' || UP.last_name) = '' THEN U.id :: TEXT ELSE UP.first_name || ' ' || UP.last_name END
) as avatar_name,
FROM
users AS U
JOIN user_profiles UP ON UP.user_id = U.id
WHERE
U.id IN ($1);`
rows, err := postgresql.Instance.Query(stm, userIDs)
defer rows.Close()
if err != nil && err != sql.ErrNoRows {
return
}
if err == sql.ErrNoRows {
return users, nil
}
for rows.Next() {
var (
id int
AvatarName string
)
err = rows.Scan(&id, &AvatarName)
if err != nil {
return nil, err
}
users = append(users, User{ID: id, AvatarName: AvatarName})
}
return users, nil
}
运行此命令时,它会给出错误 转换参数$ 1类型:不支持的类型[] interface {},接口的一部分
答案 0 :(得分:0)
rdd.collect()
更改为AttributeError: 'NoneType' object has no attribute 'group'
,以便可以使用数组值。 代码如下:
IN ($1)