postgres:带有文本[]参数失败的呼叫函数与数组文字失败
我有一个Postgres函数,该功能接受文本[]作为输入。例如
create function temp1(player_ids text[])
returns void
language plpgsql
as
$$
begin
update players set player_xp = 0
where id in (player_ids);
-- the body is actually 20 lines long, updating a lot of tables
end;
$$;
,我正在尝试称呼它,但是我一直在
[42883] ERROR: operator does not exist: text = text[] Hint: No operator matches the given name and argument types. You might need to add explicit type casts. Where: PL/pgSQL function temp1(text[]) line 3 at SQL statement
尝试这些尝试,到目前为止
select temp1('{F7AWLJWYQ5BMPKGXLMDNQKQ4NY,AQPBAFKQONGLBKIMCSOD747GY4}');
select temp1('{F7AWLJWYQ5BMPKGXLMDNQKQ4NY,AQPBAFKQONGLBKIMCSOD747GY4}'::text[]);
select temp1(array['F7AWLJWYQ5BMPKGXLMDNQKQ4NY,AQPBAFKQONGLBKIMCSOD747GY4']);
select temp1(array['F7AWLJWYQ5BMPKGXLMDNQKQ4NY,AQPBAFKQONGLBKIMCSOD747GY4']::text[]);
,我必须缺少一些明显的东西...我如何用数组字面的字面来称呼此功能?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
=任何
而不是in:
在操作员中作用于显式值列表。
在要将值与数组的每个元素进行比较时,请使用 any。
请注意,两个构建体的变体在(subquery)中的表达和。尽管在这种情况下有一个子查询似乎过多,但第一个被正确使用了。
Use
= any
instead ofin:
The IN operator acts on an explicit list of values.
When you want to compare a value to each element of an array, use ANY instead.
Note that there are variants of both constructs for subqueries expression IN (subquery) and expression operator ANY (subquery). The first one was properly used in the other answer though a subquery seems excessive in this case.
您可以使用非最重要的功能,此功能非常简单且相同的时间最佳性能。 Unnest使用将数组元素转换为行。示例:
您可以轻松地将数组元素施加到另一种类型,以便使用Unnest。
例子:
You can use unnest function, this function is very easy and same time best performanced. Unnest using for converting array elements to rows. Example:
And you can easily cast array elements to another type for using unnest.
Example: