Sqlite 将数据从 temp table 复制到另一个有冲突
Sqlite copy data from temp table to another with conflict
我有主 table 和临时 table 的 db sqlite。我想从文本文件导入数据,然后我想将数据从 temp table 插入到 main table.
INSERT INTO table(key) SELECT src.key FROM temp as src
ON CONFLICT (table.key) DO UPDATE SET to_insert = 0, to_delete =0;
当我尝试 运行 这个查询时,sqlite 向我抛出这个错误。
Query 1 ERROR: near "DO": syntax error
是否可能从另一个 table 插入数据有冲突?
select
语句需要一个 where
子句:
insert into mytable(key)
select key from temp where true
on conflict (key) do update set to_insert = 0, to_delete =0;
这个陷阱被记录为 parsing ambiguity(强调我的):
When the INSERT
statement to which the UPSERT
is attached takes its values from a SELECT
statement, there is a potential parsing ambiguity. The parser might not be able to tell if the ON
keyword is introducing the UPSERT
or if it is the ON
clause of a join. To work around this, the SELECT
statement should always include a WHERE
clause, even if that WHERE
clause is just WHERE true
.
我有主 table 和临时 table 的 db sqlite。我想从文本文件导入数据,然后我想将数据从 temp table 插入到 main table.
INSERT INTO table(key) SELECT src.key FROM temp as src
ON CONFLICT (table.key) DO UPDATE SET to_insert = 0, to_delete =0;
当我尝试 运行 这个查询时,sqlite 向我抛出这个错误。
Query 1 ERROR: near "DO": syntax error
是否可能从另一个 table 插入数据有冲突?
select
语句需要一个 where
子句:
insert into mytable(key)
select key from temp where true
on conflict (key) do update set to_insert = 0, to_delete =0;
这个陷阱被记录为 parsing ambiguity(强调我的):
When the
INSERT
statement to which theUPSERT
is attached takes its values from aSELECT
statement, there is a potential parsing ambiguity. The parser might not be able to tell if theON
keyword is introducing theUPSERT
or if it is theON
clause of a join. To work around this, theSELECT
statement should always include aWHERE
clause, even if thatWHERE
clause is justWHERE true
.