INSERT INTO flashcard ( question, answer, deck_id ) VALUES ( ?1, ?2, (SELECT id FROM deck WHERE name = ?3) ) ON CONFLICT(question, deck_id) DO UPDATE SET answer = excluded.answer;