Error: D1_ERROR: near "MERGE": syntax error at offset 3

MERGE INTO pt_player_tribe AS target
USING (SELECT ?1 AS player_id, ?2 AS tribe_id, ?3 AS world) AS source
ON (target.player_id = source.player_id AND target.world = source.world)
WHEN MATCHED AND target.tribe_id <> source.tribe_id THEN
UPDATE SET tribe_id = source.tribe_id
WHEN NOT MATCHED THEN
INSERT (player_id, world, tribe_id)
VALUES (source.player_id, source.world, source.tribe_id)
MERGE INTO pt_player_tribe AS target
USING (SELECT ?1 AS player_id, ?2 AS tribe_id, ?3 AS world) AS source
ON (target.player_id = source.player_id AND target.world = source.world)
WHEN MATCHED AND target.tribe_id <> source.tribe_id THEN
UPDATE SET tribe_id = source.tribe_id
WHEN NOT MATCHED THEN
INSERT (player_id, world, tribe_id)
VALUES (source.player_id, source.world, source.tribe_id)
1 Reply
DaniFoldi
DaniFoldi5mo ago
I believe sqlite (which is what D1 uses) doesn't support MERGE INTO.You can achieve a similar outcome with INSERT INTO and UPSERT (https://sqlite.org/lang_upsert.html)
Want results from more Discord servers?
Add your server