create or replace function decode(p_condition boolean, p_fist_val text, P_last_val text)
returns text
 as
$$
declare
 v_ret_val text;
begin
 /*
 * 功能说明:模拟三元表达式  ( condition ? value1 : value2 );
 * 参数说明:p_condition 接收 boolean类型的表达式 如: 1 = 1,  2 > 1 等; 后两个值是根据p_condition的真假对应的返回值
 * 实现原理: p_condition 为真则返回p_fist_val, 否则返回P_last_val
 */
 v_ret_val := null;
 if true = p_condition then
  v_ret_val := p_fist_val;
 elsif false = p_condition then
  v_ret_val := P_last_val;
 end if;
 return v_ret_val;
end;
$$
 language plpgsql;


-- 测试数据
select decode(1=2, 'outer', decode(1=1, 'inter1', 'inter2'));