Return values consisting of the set in Posgresql


I use to generate code. I want to return human_id using the group_id array.

-- 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 my understanding, ... IN (UNNEST($1::uuid[])); turns into IN ('...','...','...');


You can do the following:

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

or, alternatively, you can also do:

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

Answered By – mkopriva

Answer Checked By – Dawn Plyler (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.