fromSelect method

InsertStatement<Row, RS> fromSelect(
  1. BaseSelectStatement<BaseSelectStatement, dynamic> select, {
  2. required Map<TableColumn<Object>, Expression<Object>> columns,
})

Inserts rows from the select statement.

This method creates an INSERT INTO SELECT statement in SQL which will insert a row into this table for each row returned by the select statement.

The columns map describes which column from the select statement should be written into which column of the table. The keys of the map are the target column, and values are expressions added to the select statement.

For an example, see the documentation website

Implementation

InsertStatement<Row, RS> fromSelect(
  BaseSelectStatement select, {
  required Map<TableColumn, Expression> columns,
}) {
  _checkNoSource();

  LinkedHashMap<String, ColumnPosition> columnNameToSelectColumnName =
      LinkedHashMap();
  columns.forEach((key, value) {
    final position = select.structure.expressions[value];
    if (position == null) {
      throw ArgumentError.value(
        value,
        'column',
        'This column passd to insertFromSelect() was not added to the '
            'source select statement.',
      );
    }

    columnNameToSelectColumnName[key.name] = position;
  });

  source = InsertFromSelect._(select, columnNameToSelectColumnName);
  return this;
}