Postgres::addUniqueKey PHP Method

addUniqueKey() public method

Adds a unique constraint to a table
public addUniqueKey ( $table, $fields, $name = '', $tablespace = '' ) : -1
$table The table to which to add the unique key
$fields (array) An array of fields over which to add the unique key
$name (optional) The name to give the key, otherwise default name is assigned
$tablespace (optional) The tablespace for the schema, '' indicates default.
return -1
    function addUniqueKey($table, $fields, $name = '', $tablespace = '')
    {
        if (!is_array($fields) || sizeof($fields) == 0) {
            return -1;
        }
        $f_schema = $this->_schema;
        $this->fieldClean($f_schema);
        $this->fieldClean($table);
        $this->fieldArrayClean($fields);
        $this->fieldClean($name);
        $this->fieldClean($tablespace);
        $sql = "ALTER TABLE \"{$f_schema}\".\"{$table}\" ADD ";
        if ($name != '') {
            $sql .= "CONSTRAINT \"{$name}\" ";
        }
        $sql .= "UNIQUE (\"" . join('","', $fields) . "\")";
        if ($tablespace != '' && $this->hasTablespaces()) {
            $sql .= " USING INDEX TABLESPACE \"{$tablespace}\"";
        }
        return $this->execute($sql);
    }
Postgres