Postgres::createTableLike PHP Method

createTableLike() public method

Creates a new table in the database copying attribs and other properties from another table
public createTableLike ( $name, $like, $defaults = false, $constraints = false, $idx = false, $tablespace = '' )
$name The name of the table
$like an array giving the schema ans the name of the table from which attribs are copying from: array( 'table' => table name, 'schema' => the schema name, )
$defaults if true, copy the defaults values as well
$constraints if true, copy the constraints as well (CHECK on table & attr)
$tablespace The tablespace name ('' means none/default)
    function createTableLike($name, $like, $defaults = false, $constraints = false, $idx = false, $tablespace = '')
    {
        $f_schema = $this->_schema;
        $this->fieldClean($f_schema);
        $this->fieldClean($name);
        $this->fieldClean($like['schema']);
        $this->fieldClean($like['table']);
        $like = "\"{$like['schema']}\".\"{$like['table']}\"";
        $status = $this->beginTransaction();
        if ($status != 0) {
            return -1;
        }
        $sql = "CREATE TABLE \"{$f_schema}\".\"{$name}\" (LIKE {$like}";
        if ($defaults) {
            $sql .= " INCLUDING DEFAULTS";
        }
        if ($this->hasCreateTableLikeWithConstraints() && $constraints) {
            $sql .= " INCLUDING CONSTRAINTS";
        }
        if ($this->hasCreateTableLikeWithIndexes() && $idx) {
            $sql .= " INCLUDING INDEXES";
        }
        $sql .= ")";
        if ($this->hasTablespaces() && $tablespace != '') {
            $this->fieldClean($tablespace);
            $sql .= " TABLESPACE \"{$tablespace}\"";
        }
        $status = $this->execute($sql);
        if ($status) {
            $this->rollbackTransaction();
            return -1;
        }
        return $this->endTransaction();
    }
Postgres