【发布时间】:2017-10-12 16:37:25
【问题描述】:
我正在尝试编写一个 postgresql 函数,该函数接受一个数组并返回用户没有属于该数组的 id。我写了这样的东西:
CREATE OR REPLACE FUNCTION user_api.get_user(banned_list TEXT[])
RETURNS SETOF JSONB
AS $$
SELECT to_jsonb(result)
FROM (
SELECT
*
FROM my_user.user_info
WHERE my_user.user_info.user_id NOT IN (banned_list::TEXT[])
) AS result;
$$ LANGUAGE SQL SECURITY DEFINER;
但它会抛出这样的错误
ERROR: operator does not exist text <> text[]
LINE 24: ... WHERE my_user.user_info.user_id NOT IN (no...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
我也试过用 CAST 函数,不行。
提前感谢您的帮助。
【问题讨论】:
标签: sql database postgresql database-design