英文:
Return values consisting of the set in Posgresql
问题
我使用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 ('...', '...', '...');
英文:
I use https://github.com/kyleconroy/sqlc 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[]));
return
ERROR: set-returning functions are not allowed in WHERE (SQLSTATE 0A000)
In my understanding, ... IN (UNNEST($1::uuid[]));
turns into IN ('...','...','...');
答案1
得分: 1
你可以进行以下操作:
WHERE group_id IN (SELECT col FROM UNNEST($1::uuid[]) AS col);
或者,你也可以使用以下方式:
WHERE group_id = ANY ($1::uuid[]);
英文:
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[]);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论