1

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

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

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

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

4

1 回答 1

1

您可以执行以下操作:

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

或者,您也可以这样做:

WHERE group_id = ANY ($1::uuid[]);
于 2022-02-25T14:50:43.620 回答