if函数说明:
在mysql中if()函数的用法类似于java中的三目表达式,其用处也比较多,具体语法如下:
IF(expr1,expr2,expr3),如果expr1的值为true,则返回expr2的值,如果expr1的值为false,则返回expr3的值
postgresql自定义if函数兼容:
```sql
create or replace function if(bln boolean,inValue1 anyelement,inValue2 anyelement)
returns anyelement as
$$
begin
if bln=true then
return inValue1;
else
return inValue2;
end if;
end;
$$
language plpgsql;
create or replace function if(bln boolean,inValue1 numeric,inValue2 numeric)
returns numeric as
$$
begin
if bln=true then
return inValue1;
else
return inValue2;
end if;
end;
$$
language plpgsql;
create or replace function if(bln boolean,inValue1 numeric,inValue2 text)
returns text as
$$
begin
if bln=true then
return inValue1;
else
return inValue2;
end if;
end;
$$
language plpgsql;