protected function compileInsertFromSelect(
        $table,
        string $tableAlias = null,
        array $columns = null,
        $selectQuery
    ): StatementInterface {
        $bindings = [];

        $sqlLine1 = 'INSERT INTO '.$this->compileIdentifierWithAlias($table, $tableAlias, $bindings);
        if ($columns !== null) {
            $sqlLine1 .= ' ('.implode(', ', array_map([$this, 'quoteCompositeIdentifier'], $columns)).')';
        }

        $sqlLine2 = $this->compileSubQuery($selectQuery, $bindings, false);

        return new Raw($this->implodeSQL([$sqlLine1, $sqlLine2]), $bindings);
    }
protected function compileInsertFromSelect(
        $table,
        string $tableAlias = null,
        array $columns = null,
        $selectQuery
    ): StatementInterface {
        $bindings = [];

        $sqlLine1 = 'INSERT INTO '.$this->compileIdentifierWithAlias($table, $tableAlias, $bindings);
        if ($columns !== null) {
            $sqlLine1 .= ' ('.implode(', ', array_map([$this, 'quoteCompositeIdentifier'], $columns)).')';
        }

        $sqlLine2 = $this->compileSubQuery($selectQuery, $bindings, false);

        return new Raw($this->implodeSQL([$sqlLine1, $sqlLine2]), $bindings);
    }
protected function compileInsertFromSelect ( $ table , string $ tableAlias = null , array $ columns = null , $ selectQuery ) : StatementInterface { $ bindings = [ ] ; $ sqlLine1 = 'INSERT INTO ' . $ this -> compileIdentifierWithAlias ( $ table , $ tableAlias , $ bindings ) ; if ( $ columns !== null ) { $ sqlLine1 .= ' (' . implode ( ', ' , array_map ( [ $ this , 'quoteCompositeIdentifier' ] , $ columns ) ) . ')' ; } $ sqlLine2 = $ this -> compileSubQuery ( $ selectQuery , $ bindings , false ) ; return new Raw ( $ this -> implodeSQL ( [ $ sqlLine1 , $ sqlLine2 ] ) , $ bindings ) ; }
Compiles a full INSERT query from a select query.

@param string|Query|StatementInterface $table Target table name
@param string|null $tableAlias Table alias
@param string[]|null $columns Columns of a target table. If null, the list of columns is omitted.
@param Query|StatementInterface $selectQuery The select query
@return StatementInterface
@throws InvalidQueryException
Compiles a full INSERT query from a select query .