private function createFunction($func, array $arguments = array(), $alias = null)
    {
        // Prepare function arguments
        foreach ($arguments as $index => $argument) {
            if ($argument instanceof RawSqlFragmentInterface) {
                $item = $argument->getFragment();
            } else {
                $item = $this->quote($argument);
            }

            // Update item collection
            $arguments[$index] = $item;
        }

        $fragment = sprintf(' %s(%s) ', $func, implode(', ', $arguments));

        // Generate alias if provided
        if (!is_null($alias)) {
            $fragment .= sprintf(' AS %s ', $this->quote($alias));
        }

        // Append a comma if there was a function call before
        if ($this->hasFunctionCall === true) {
            $this->append(', ');
        }

        $this->hasFunctionCall = true;
        return $fragment;
    }