首页 > 解决方案 > INSERT query type is not supported yet. You can use:SELECT, DELETE, UPDATE

问题描述

I am getting this compile error when I try this query. 

INSERT query type is not supported yet. You can use:SELECT, DELETE, UPDATE

@Query("INSERT INTO table SELECT name, etc from temp_table;") 
void insertIntoTable();

Is there any other way to do a batch insert?

标签: android-room

解决方案


I was able to do it using RawQuery:

public void addRecordsFromTempTable() {
    mDatabase.rawDao().insertRecords(new SimpleSQLiteQuery("INSERT INTO my_table (name, etc) SELECT name, et from temp_table;"));
}

Raw query file:

@Dao
public interface RawDao {
    @RawQuery()
    boolean insertRecords(SupportSQLiteQuery query);

推荐阅读