【发布时间】:2015-10-18 16:05:32
【问题描述】:
如何从使用case 语句的用户定义函数中设置值(或直接返回值)?
create function is_bar(email varchar) returns boolean as
$$
declare returnValue boolean;
begin
select case when exists
(select * from (users join user_roles on users.userID = user_roles.userID)
where user_email=email and user_role='bar')
then (returnValue := TRUE);
else (returnValue := FALSE);
end;
return returnValue;
end;
$$ language plpgsql;
给我:
ERROR: syntax error at or near ":="
LINE 8: then (returnValue := TRUE);
【问题讨论】:
-
您不能分配这样的变量。你需要使用PL/pgSQL的
select into:postgresql.org/docs/current/static/… -
@a_horse_with_no_name 感谢您的提醒
标签: sql postgresql syntax-error case plpgsql