我有两张这样的表:
check_value1
t
check_value2
f
每个表总是有一个列和一个包含布尔值的行。
我想在plpgsql的if..then..else条件中使用这些表,如下所示:
CREATE FUNCTION if_logic()
RETURNS void AS
$$
IF check_value1 is true and check_value2 is true THEN operation1
ELIF check_value1 is false and check_value2 is false THEN operation2
ELSE operation3
$$
language plpgsql
如何做到这一点?
答案 0 :(得分:0)
create function if_logic()
returns void as $$
begin
select case
when cv1.check_value and cv2.check_value then operation1
when not cv1.check_value and not cv2.check_value then operation2
else operation3
end
from check_value1 cv1 cross join check_value2 cv2
;
end;
$$ language plpgsql;