function getFunctions($all = false, $type = null)
{
if ($all) {
$where = 'pg_catalog.pg_function_is_visible(p.oid)';
$distinct = 'DISTINCT ON (p.proname)';
if ($type) {
$where .= " AND p.prorettype = (select oid from pg_catalog.pg_type p where p.typname = 'trigger') ";
}
} else {
$c_schema = $this->_schema;
$this->clean($c_schema);
$where = "n.nspname = '{$c_schema}'";
$distinct = '';
}
$sql = "\n\t\t\tSELECT\n\t\t\t\t{$distinct}\n\t\t\t\tp.oid AS prooid,\n\t\t\t\tp.proname,\n\t\t\t\tp.proretset,\n\t\t\t\tpg_catalog.format_type(p.prorettype, NULL) AS proresult,\n\t\t\t\tpg_catalog.oidvectortypes(p.proargtypes) AS proarguments,\n\t\t\t\tpl.lanname AS prolanguage,\n\t\t\t\tpg_catalog.obj_description(p.oid, 'pg_proc') AS procomment,\n\t\t\t\tp.proname || ' (' || pg_catalog.oidvectortypes(p.proargtypes) || ')' AS proproto,\n\t\t\t\tCASE WHEN p.proretset THEN 'setof ' ELSE '' END || pg_catalog.format_type(p.prorettype, NULL) AS proreturns,\n\t\t\t\tu.usename AS proowner\n\t\t\tFROM pg_catalog.pg_proc p\n\t\t\t\tINNER JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n\t\t\t\tINNER JOIN pg_catalog.pg_language pl ON pl.oid = p.prolang\n\t\t\t\tLEFT JOIN pg_catalog.pg_user u ON u.usesysid = p.proowner\n\t\t\tWHERE NOT p.proisagg\n\t\t\t\tAND {$where}\n\t\t\tORDER BY p.proname, proresult\n\t\t\t";
return $this->selectSet($sql);
}