Postgres::createAggregate PHP Method

createAggregate() public method

Creates a new aggregate in the database
public createAggregate ( $name, $basetype, $sfunc, $stype, $ffunc, $initcond, $sortop, $comment ) : -1
$name The name of the aggregate
$basetype The input data type of the aggregate
$sfunc The name of the state transition function for the aggregate
$stype The data type for the aggregate's state value
$ffunc The name of the final function for the aggregate
$initcond The initial setting for the state value
$sortop The sort operator for the aggregate
$comment Aggregate comment
return -1
    function createAggregate($name, $basetype, $sfunc, $stype, $ffunc, $initcond, $sortop, $comment)
    {
        $f_schema = $this->_schema;
        $this->fieldClean($f_schema);
        $this->fieldClean($name);
        $this->fieldClean($basetype);
        $this->fieldClean($sfunc);
        $this->fieldClean($stype);
        $this->fieldClean($ffunc);
        $this->fieldClean($initcond);
        $this->fieldClean($sortop);
        $this->beginTransaction();
        $sql = "CREATE AGGREGATE \"{$f_schema}\".\"{$name}\" (BASETYPE = \"{$basetype}\", SFUNC = \"{$sfunc}\", STYPE = \"{$stype}\"";
        if (trim($ffunc) != '') {
            $sql .= ", FINALFUNC = \"{$ffunc}\"";
        }
        if (trim($initcond) != '') {
            $sql .= ", INITCOND = \"{$initcond}\"";
        }
        if (trim($sortop) != '') {
            $sql .= ", SORTOP = \"{$sortop}\"";
        }
        $sql .= ")";
        $status = $this->execute($sql);
        if ($status) {
            $this->rollbackTransaction();
            return -1;
        }
        if (trim($comment) != '') {
            $status = $this->setComment('AGGREGATE', $name, '', $comment, $basetype);
            if ($status) {
                $this->rollbackTransaction();
                return -1;
            }
        }
        return $this->endTransaction();
    }
Postgres