Postgres::createIndex PHP Method

createIndex() public method

Creates an index
public createIndex ( $name, $table, $columns, $type, $unique, $where, $tablespace, $concurrently )
$name The index name
$table The table on which to add the index
$columns An array of columns that form the index or a string expression for a functional index
$type The index type
$unique True if unique, false otherwise
$where Index predicate ('' for none)
$tablespace The tablespaces ('' means none/default)
    function createIndex($name, $table, $columns, $type, $unique, $where, $tablespace, $concurrently)
    {
        $f_schema = $this->_schema;
        $this->fieldClean($f_schema);
        $this->fieldClean($name);
        $this->fieldClean($table);
        $sql = "CREATE";
        if ($unique) {
            $sql .= " UNIQUE";
        }
        $sql .= " INDEX";
        if ($concurrently) {
            $sql .= " CONCURRENTLY";
        }
        $sql .= " \"{$name}\" ON \"{$f_schema}\".\"{$table}\" USING {$type} ";
        if (is_array($columns)) {
            $this->arrayClean($columns);
            $sql .= "(\"" . implode('","', $columns) . "\")";
        } else {
            $sql .= "(" . $columns . ")";
        }
        // Tablespace
        if ($this->hasTablespaces() && $tablespace != '') {
            $this->fieldClean($tablespace);
            $sql .= " TABLESPACE \"{$tablespace}\"";
        }
        // Predicate
        if (trim($where) != '') {
            $sql .= " WHERE ({$where})";
        }
        return $this->execute($sql);
    }
Postgres