forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit168d580
committed
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative toraising a unique or exclusion constraint violation error when inserting.ON CONFLICT refers to constraints that can either be specified using ainference clause (by specifying the columns of a unique constraint) orby naming a unique or exclusion constraint. DO NOTHING avoids theconstraint violation, without touching the pre-existing row. DO UPDATESET ... [WHERE ...] updates the pre-existing tuple, and has access toboth the tuple proposed for insertion and the existing tuple; theoptional WHERE clause can be used to prevent an update from beingexecuted. The UPDATE SET and WHERE clauses have access to the tupleproposed for insertion using the "magic" EXCLUDED alias, and to thepre-existing tuple using the table name or its alias.This feature is often referred to as upsert.This is implemented using a new infrastructure called "speculativeinsertion". It is an optimistic variant of regular insertion that firstdoes a pre-check for existing tuples and then attempts an insert. If aviolating tuple was inserted concurrently, the speculatively insertedtuple is deleted and a new attempt is made. If the pre-check finds amatching tuple the alternative DO NOTHING or DO UPDATE action is taken.If the insertion succeeds without detecting a conflict, the tuple isdeemed inserted.To handle the possible ambiguity between the excluded alias and a tablenamed excluded, and for convenience with long relation names, INSERTINTO now can alias its target table.Bumps catversion as stored rules change.Author: Peter Geoghegan, with significant contributions from Heikki Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs, Dean Rasheed, Stephen Frost and many others.1 parent2c8f483 commit168d580
File tree
122 files changed
+6106
-435
lines changed- contrib
- pg_stat_statements
- postgres_fdw
- expected
- sql
- test_decoding
- expected
- sql
- doc/src/sgml
- ref
- src
- backend
- access
- heap
- nbtree
- rmgrdesc
- catalog
- commands
- executor
- nodes
- optimizer
- plan
- prep
- util
- parser
- replication/logical
- rewrite
- storage/lmgr
- tcop
- utils
- adt
- time
- bin/psql
- include
- access
- catalog
- executor
- nodes
- optimizer
- parser
- replication
- rewrite
- storage
- utils
- test
- isolation
- expected
- specs
- regress
- expected
- input
- output
- sql
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
122 files changed
+6106
-435
lines changedLines changed: 25 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2264 | 2264 |
| |
2265 | 2265 |
| |
2266 | 2266 |
| |
| 2267 | + | |
2267 | 2268 |
| |
2268 | 2269 |
| |
2269 | 2270 |
| |
| |||
2631 | 2632 |
| |
2632 | 2633 |
| |
2633 | 2634 |
| |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
| 2640 | + | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
2634 | 2645 |
| |
2635 | 2646 |
| |
2636 | 2647 |
| |
| |||
2667 | 2678 |
| |
2668 | 2679 |
| |
2669 | 2680 |
| |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
2670 | 2695 |
| |
2671 | 2696 |
| |
2672 | 2697 |
| |
|
Lines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
847 | 847 |
| |
848 | 848 |
| |
849 | 849 |
| |
850 |
| - | |
851 |
| - | |
| 850 | + | |
| 851 | + | |
852 | 852 |
| |
853 | 853 |
| |
854 | 854 |
| |
| |||
892 | 892 |
| |
893 | 893 |
| |
894 | 894 |
| |
| 895 | + | |
| 896 | + | |
| 897 | + | |
895 | 898 |
| |
896 | 899 |
| |
897 | 900 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2327 | 2327 |
| |
2328 | 2328 |
| |
2329 | 2329 |
| |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
2330 | 2335 |
| |
2331 | 2336 |
| |
2332 | 2337 |
| |
|
Lines changed: 14 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1171 | 1171 |
| |
1172 | 1172 |
| |
1173 | 1173 |
| |
| 1174 | + | |
1174 | 1175 |
| |
1175 | 1176 |
| |
1176 | 1177 |
| |
| |||
1222 | 1223 |
| |
1223 | 1224 |
| |
1224 | 1225 |
| |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
1225 | 1238 |
| |
1226 | 1239 |
| |
1227 | 1240 |
| |
1228 | 1241 |
| |
1229 | 1242 |
| |
1230 | 1243 |
| |
1231 | 1244 |
| |
1232 |
| - | |
| 1245 | + | |
1233 | 1246 |
| |
1234 | 1247 |
| |
1235 | 1248 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
60 | 60 |
| |
61 | 61 |
| |
62 | 62 |
| |
63 |
| - | |
| 63 | + | |
64 | 64 |
| |
65 | 65 |
| |
66 | 66 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
372 | 372 |
| |
373 | 373 |
| |
374 | 374 |
| |
| 375 | + | |
| 376 | + | |
| 377 | + | |
375 | 378 |
| |
376 | 379 |
| |
377 | 380 |
| |
|
Lines changed: 34 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
148 | 148 |
| |
149 | 149 |
| |
150 | 150 |
| |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
151 | 169 |
| |
152 | 170 |
| |
153 | 171 |
| |
| |||
196 | 214 |
| |
197 | 215 |
| |
198 | 216 |
| |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
199 | 233 |
| |
200 | 234 |
| |
201 | 235 |
| |
|
Lines changed: 8 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
23 | 23 |
| |
24 | 24 |
| |
25 | 25 |
| |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
26 | 30 |
| |
27 | 31 |
| |
28 | 32 |
| |
| |||
64 | 68 |
| |
65 | 69 |
| |
66 | 70 |
| |
| 71 | + | |
| 72 | + | |
| 73 | + | |
67 | 74 |
| |
68 | 75 |
| |
69 | 76 |
| |
| |||
283 | 290 |
| |
284 | 291 |
| |
285 | 292 |
| |
286 |
| - | |
| 293 | + | |
287 | 294 |
| |
288 | 295 |
| |
289 | 296 |
| |
|
Lines changed: 22 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
84 | 84 |
| |
85 | 85 |
| |
86 | 86 |
| |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
87 | 99 |
| |
88 | 100 |
| |
89 | 101 |
| |
| |||
114 | 126 |
| |
115 | 127 |
| |
116 | 128 |
| |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
117 | 139 |
| |
118 | 140 |
| |
119 | 141 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
25 | 25 |
| |
26 | 26 |
| |
27 | 27 |
| |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
28 | 33 |
| |
29 | 34 |
| |
30 | 35 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1050 | 1050 |
| |
1051 | 1051 |
| |
1052 | 1052 |
| |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
1053 | 1060 |
| |
1054 | 1061 |
| |
1055 | 1062 |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
853 | 853 |
| |
854 | 854 |
| |
855 | 855 |
| |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
856 | 863 |
| |
857 | 864 |
| |
858 | 865 |
| |
|
Lines changed: 21 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
326 | 326 |
| |
327 | 327 |
| |
328 | 328 |
| |
329 |
| - | |
330 |
| - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
331 | 350 |
| |
332 | 351 |
| |
333 | 352 |
| |
|
Lines changed: 10 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2623 | 2623 |
| |
2624 | 2624 |
| |
2625 | 2625 |
| |
2626 |
| - | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
2627 | 2631 |
| |
2628 | 2632 |
| |
2629 | 2633 |
| |
| |||
3852 | 3856 |
| |
3853 | 3857 |
| |
3854 | 3858 |
| |
3855 |
| - | |
3856 |
| - | |
3857 |
| - | |
| 3859 | + | |
| 3860 | + | |
| 3861 | + | |
| 3862 | + | |
| 3863 | + | |
3858 | 3864 |
| |
3859 | 3865 |
| |
3860 | 3866 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
68 | 68 |
| |
69 | 69 |
| |
70 | 70 |
| |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
71 | 79 |
| |
72 | 80 |
| |
73 | 81 |
| |
|
Lines changed: 10 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2998 | 2998 |
| |
2999 | 2999 |
| |
3000 | 3000 |
| |
3001 |
| - | |
3002 |
| - | |
3003 |
| - | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
3004 | 3011 |
| |
3005 | 3012 |
| |
3006 | 3013 |
| |
|
0 commit comments
Comments
(0)