문제

In a large database, I'm using a very long query similar to this:

INSERT INTO t VALUES (@p_1); SELECT last_insert_rowid() as i_1;
INSERT INTO t VALUES (@p_2); SELECT last_insert_rowid() as i_2;
...

This allows for infinitely faster insertion compared to single transactions. However, I was surprised that only one value is returned instead of one per SELECT.

Usually, this is a non-issue because it is easy to use only one rowid and calculate the others from it (autoincrement issues may be an exception). However, for the sake of understanding (and disregarding that I probably abuse SQLite): Why is this happening, and how could I still use multiple SELECTs in a single transaction?

도움이 되었습니까?

해결책

try with temp table like below

PRAGMA temp_store = MEMORY;
CREATE TEMP TABLE TempIds (id INTEGER);

INSERT INTO t VALUES (@p_1); INSERT INTO TempIds VALUES(last_insert_rowid());
INSERT INTO t VALUES (@p_2);  INSERT INTO TempIds VALUES(last_insert_rowid());
...

SELECT id FROM TempIds;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top