如何從使用case
語句的用戶定義函數中設置值(或直接返回值)?plpgsql中的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':http://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW –
@a_horse_with_no_name感謝您的支持 – beoliver