select
Specifies that the data for the INSERT statement will come from a SELECT query.
This allows for INSERT INTO ... SELECT ... statements, which are useful for copying or transforming data from one or more tables into the target table.
The number and types of columns returned by the selectStatement must match the columns specified when the InsertStatement was created. If no columns were specified (e.g., table.insert()), the SELECT statement's columns must match all insertable columns of the target table in their defined order.
Example:
// INSERT INTO ArchivedArtists (artistId, artistName)
// SELECT artistId, artistName FROM Artists WHERE lastActiveYear < 2000;
ArchivedArtists
.insert(
ArchivedArtists.artistId,
ArchivedArtists.artistName
).use {
it.select {
Artists
.select(Artists.artistId, Artists.artistName)
.where { Artists.lastActiveYear LT 2000 }
}.execute()
}Return
This InsertStatement instance, allowing for method chaining.
Author
MOHAMMAD AZIM ANSARI
Parameters
A lambda function that returns a configured SelectStatement. The result of this SELECT query provides the rows to be inserted.