Return 个 values 由 Postgresql 中的集合组成

Return values consisting of the set in Posgresql

我使用https://github.com/kyleconroy/sqlc生成代码。我想 return human_id 使用 group_id 数组。

-- name: HumansByGroupID :many
SELECT human_id FROM groups
WHERE group_id IN (UNNEST(::uuid[]));

return ERROR: set-returning functions are not allowed in WHERE (SQLSTATE 0A000)

在我的理解中,... IN (UNNEST(::uuid[]));变成了IN ('...','...','...');

您可以执行以下操作:

WHERE group_id IN (SELECT col FROM UNNEST(::uuid[]) AS col);

或者,您也可以这样做:

WHERE group_id = ANY (::uuid[]);