insertFromSelect method

Future<void> insertFromSelect(
  1. BaseSelectStatement select, {
  2. required Map<Column<Object>, Expression<Object>> columns,
  3. InsertMode mode = InsertMode.insert,
  4. UpsertClause<T, D>? onConflict,
})

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

Future<void> insertFromSelect(
  BaseSelectStatement select, {
  required Map<Column, Expression> columns,
  InsertMode mode = InsertMode.insert,
  UpsertClause<T, D>? onConflict,
}) async {
  final ctx =
      createContextFromSelect(select, columns, mode, onConflict: onConflict);

  return await database.withCurrentExecutor((e) async {
    await e.runInsert(ctx.sql, ctx.boundVariables);
    database
        .notifyUpdates({TableUpdate.onTable(table, kind: UpdateKind.insert)});
  });
}