Postgres::createDomain PHP Method

createDomain() public method

Creates a domain
public createDomain ( $domain, $type, $length, $array, $notnull, $default, $check )
$domain The name of the domain to create
$type The base type for the domain
$length Optional type length
$array True for array type, false otherwise
$notnull True for NOT NULL, false otherwise
$default Default value for domain
$check A CHECK constraint if there is one
    function createDomain($domain, $type, $length, $array, $notnull, $default, $check)
    {
        $f_schema = $this->_schema;
        $this->fieldClean($f_schema);
        $this->fieldClean($domain);
        $sql = "CREATE DOMAIN \"{$f_schema}\".\"{$domain}\" AS ";
        if ($length == '') {
            $sql .= $type;
        } else {
            switch ($type) {
                // Have to account for weird placing of length for with/without
                // time zone types
                case 'timestamp with time zone':
                case 'timestamp without time zone':
                    $qual = substr($type, 9);
                    $sql .= "timestamp({$length}){$qual}";
                    break;
                case 'time with time zone':
                case 'time without time zone':
                    $qual = substr($type, 4);
                    $sql .= "time({$length}){$qual}";
                    break;
                default:
                    $sql .= "{$type}({$length})";
            }
        }
        // Add array qualifier, if requested
        if ($array) {
            $sql .= '[]';
        }
        if ($notnull) {
            $sql .= ' NOT NULL';
        }
        if ($default != '') {
            $sql .= " DEFAULT {$default}";
        }
        if ($this->hasDomainConstraints() && $check != '') {
            $sql .= " CHECK ({$check})";
        }
        return $this->execute($sql);
    }
Postgres