postgresql版本是8.2.15。
最近陆续有数据分析师从impala、hive转到查询gpdb,gpdb虽然能够支持在查询语句中带多个distinct,但是缺少相应的if、ifnull、group_concat函数,正好年后有空就拓展一些函数给他们用
1. to_array聚集函数
CREATE AGGREGATE pg_catalog.to_array (anyelement)
(
sfunc = array_append,
stype = anyarray,
initcond = '{}'
);
2. if函数
create function if(expr bool, true_result anyelement, false_result anyelement) RETURNS anyelement AS
$$
BEGIN
if expr then return true_result;
else return false_result;
end if;
END;
$$
LANGUAGE plpgsql;
3. ifnull函数
create function ifnull(value anyelement, null_value anyelement) RETURNS anyelement AS
$$
BEGIN
if value is null then return null_value;
else return value;
end if;
END;
$$
LANGUAGE plpgsql;