返回由PostgreSQL中的集合组成的返回值。

huangapple go评论78阅读模式
英文:

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[]);

huangapple
  • 本文由 发表于 2022年2月25日 20:08:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/71265646.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定