Commit 8c7955d
committed
Add opt-in INSERT IGNORE support for MySQL via conflict_target
The default on_conflict: :nothing behavior now uses the ON DUPLICATE KEY
UPDATE x = x workaround (restoring original behavior), which always reports
1 affected row regardless of whether the row was inserted or ignored.
For users who need accurate row counts (0 when ignored, 1 when inserted),
INSERT IGNORE can be explicitly enabled via:
Repo.insert_all(Post, posts,
on_conflict: :nothing,
conflict_target: {:unsafe_fragment, "insert_ignore"})
This approach was chosen to avoid modifying Ecto core with a new on_conflict
type like :ignore for MySQL-specific intricacies. By leveraging the existing
{:unsafe_fragment, _} mechanism, MySQL users can opt into INSERT IGNORE
semantics when needed while maintaining backward compatibility.
Note that INSERT IGNORE has broader semantics in MySQL - it ignores certain
type conversion errors in addition to duplicate key conflicts - which is why
it's not the default behavior.1 parent 7478895 commit 8c7955d
File tree
4 files changed
+96
-29
lines changed- integration_test/myxql
- lib/ecto/adapters
- myxql
- test/ecto/adapters
4 files changed
+96
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
18 | 30 | | |
19 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
20 | 35 | | |
21 | 36 | | |
22 | | - | |
| 37 | + | |
23 | 38 | | |
24 | 39 | | |
25 | 40 | | |
26 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
27 | 46 | | |
28 | 47 | | |
29 | 48 | | |
30 | 49 | | |
31 | 50 | | |
32 | 51 | | |
33 | | - | |
34 | | - | |
35 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
36 | 55 | | |
37 | 56 | | |
38 | 57 | | |
39 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
40 | 62 | | |
41 | 63 | | |
42 | 64 | | |
43 | 65 | | |
44 | 66 | | |
45 | 67 | | |
46 | | - | |
| 68 | + | |
47 | 69 | | |
48 | 70 | | |
49 | 71 | | |
50 | 72 | | |
51 | 73 | | |
52 | 74 | | |
53 | | - | |
| 75 | + | |
54 | 76 | | |
55 | 77 | | |
56 | 78 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
62 | 85 | | |
63 | 86 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 87 | + | |
| 88 | + | |
68 | 89 | | |
69 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
70 | 94 | | |
71 | 95 | | |
72 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
106 | 123 | | |
107 | 124 | | |
108 | 125 | | |
| |||
330 | 347 | | |
331 | 348 | | |
332 | 349 | | |
333 | | - | |
334 | | - | |
| 350 | + | |
| 351 | + | |
335 | 352 | | |
336 | | - | |
| 353 | + | |
337 | 354 | | |
338 | 355 | | |
339 | 356 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
197 | 200 | | |
198 | 201 | | |
199 | 202 | | |
| |||
212 | 215 | | |
213 | 216 | | |
214 | 217 | | |
215 | | - | |
216 | | - | |
| 218 | + | |
| 219 | + | |
217 | 220 | | |
218 | 221 | | |
219 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
220 | 229 | | |
221 | 230 | | |
222 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1465 | 1465 | | |
1466 | 1466 | | |
1467 | 1467 | | |
1468 | | - | |
1469 | | - | |
| 1468 | + | |
| 1469 | + | |
1470 | 1470 | | |
1471 | | - | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
1472 | 1474 | | |
1473 | 1475 | | |
1474 | 1476 | | |
| |||
1498 | 1500 | | |
1499 | 1501 | | |
1500 | 1502 | | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
1501 | 1518 | | |
1502 | 1519 | | |
1503 | 1520 | | |
| |||
0 commit comments