forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitd204ef6
committed
MERGE SQL Command following SQL:2016
MERGE performs actions that modify rows in the target tableusing a source table or query. MERGE provides a single SQLstatement that can conditionally INSERT/UPDATE/DELETE rowsa task that would other require multiple PL statements.e.g.MERGE INTO target AS tUSING source AS sON t.tid = s.sidWHEN MATCHED AND t.balance > s.delta THEN UPDATE SET balance = t.balance - s.deltaWHEN MATCHED THEN DELETEWHEN NOT MATCHED AND s.delta > 0 THEN INSERT VALUES (s.sid, s.delta)WHEN NOT MATCHED THEN DO NOTHING;MERGE works with regular and partitioned tables, includingcolumn and row security enforcement, as well as support forrow, statement and transition triggers.MERGE is optimized for OLTP and is parameterizable, thoughalso useful for large scale ETL/ELT. MERGE is not intendedto be used in preference to existing single SQL commandsfor INSERT, UPDATE or DELETE since there is some overhead.MERGE can be used statically from PL/pgSQL.MERGE does not yet support inheritance, write rules,RETURNING clauses, updatable views or foreign tables.MERGE follows SQL Standard per the most recent SQL:2016.Includes full tests and documentation, including fullisolation tests to demonstrate the concurrent behavior.This version written from scratch in 2017 by Simon Riggs,using docs and tests originally written in 2009. Later workfrom Pavan Deolasee has been both complex and deep, leavingthe lead author credit now in his hands.Extensive discussion of concurrency from Peter Geoghegan,with thanks for the time and effort contributed.Various issues reported via sqlsmith by Andreas SeltenreichAuthors: Pavan Deolasee, Simon RiggsReviewer: Peter Geoghegan, Amit Langote, Tomas Vondra, Simon RiggsDiscussion:https://postgr.es/m/CANP8+jKitBSrB7oTgT9CY2i1ObfOt36z0XMraQc+Xrz8QB0nXA@mail.gmail.comhttps://postgr.es/m/CAH2-WzkJdBuxj9PO=2QaO9-3h3xGbQPZ34kJH=HukRekwM-GZg@mail.gmail.com1 parentaa5877b commitd204ef6
File tree
82 files changed
+2600
-165
lines changed- contrib/test_decoding
- expected
- sql
- doc/src/sgml
- ref
- src
- backend
- access/heap
- catalog
- commands
- executor
- nodes
- optimizer
- plan
- prep
- util
- parser
- rewrite
- tcop
- include
- access
- commands
- executor
- nodes
- optimizer
- parser
- rewrite
- interfaces/libpq
- pl/plpgsql/src
- test
- isolation
- regress
- expected
- sql
- tools/pgindent
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
82 files changed
+2600
-165
lines changedLines changed: 46 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
192 | 192 |
| |
193 | 193 |
| |
194 | 194 |
| |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
195 | 241 |
| |
196 | 242 |
| |
197 | 243 |
| |
|
Lines changed: 16 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
93 | 93 |
| |
94 | 94 |
| |
95 | 95 |
| |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
96 | 112 |
| |
97 | 113 |
| |
98 | 114 |
| |
|
Lines changed: 5 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3917 | 3917 |
| |
3918 | 3918 |
| |
3919 | 3919 |
| |
3920 |
| - | |
3921 |
| - | |
3922 |
| - | |
| 3920 | + | |
| 3921 | + | |
| 3922 | + | |
| 3923 | + | |
| 3924 | + | |
3923 | 3925 |
| |
3924 | 3926 |
| |
3925 | 3927 |
| |
|
Lines changed: 27 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
422 | 422 |
| |
423 | 423 |
| |
424 | 424 |
| |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
425 | 450 |
| |
426 | 451 |
| |
427 | 452 |
| |
| |||
900 | 925 |
| |
901 | 926 |
| |
902 | 927 |
| |
903 |
| - | |
| 928 | + | |
| 929 | + | |
904 | 930 |
| |
905 | 931 |
| |
906 | 932 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1246 | 1246 |
| |
1247 | 1247 |
| |
1248 | 1248 |
| |
1249 |
| - | |
| 1249 | + | |
1250 | 1250 |
| |
1251 | 1251 |
| |
1252 | 1252 |
| |
| |||
1529 | 1529 |
| |
1530 | 1530 |
| |
1531 | 1531 |
| |
| 1532 | + | |
1532 | 1533 |
| |
1533 | 1534 |
| |
1534 | 1535 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
159 | 159 |
| |
160 | 160 |
| |
161 | 161 |
| |
| 162 | + | |
162 | 163 |
| |
163 | 164 |
| |
164 | 165 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
94 | 94 |
| |
95 | 95 |
| |
96 | 96 |
| |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
97 | 104 |
| |
98 | 105 |
| |
99 | 106 |
| |
|
Lines changed: 10 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
579 | 579 |
| |
580 | 580 |
| |
581 | 581 |
| |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
582 | 589 |
| |
583 | 590 |
| |
584 | 591 |
| |
| |||
749 | 756 |
| |
750 | 757 |
| |
751 | 758 |
| |
752 |
| - | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
753 | 762 |
| |
754 | 763 |
| |
755 | 764 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
186 | 186 |
| |
187 | 187 |
| |
188 | 188 |
| |
| 189 | + | |
189 | 190 |
| |
190 | 191 |
| |
191 | 192 |
| |
|
Lines changed: 20 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
182 | 182 |
| |
183 | 183 |
| |
184 | 184 |
| |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
185 | 205 |
| |
186 | 206 |
| |
187 | 207 |
| |
|
Lines changed: 16 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3245 | 3245 |
| |
3246 | 3246 |
| |
3247 | 3247 |
| |
| 3248 | + | |
3248 | 3249 |
| |
3249 | 3250 |
| |
3250 | 3251 |
| |
| |||
3507 | 3508 |
| |
3508 | 3509 |
| |
3509 | 3510 |
| |
3510 |
| - | |
| 3511 | + | |
3511 | 3512 |
| |
3512 | 3513 |
| |
3513 | 3514 |
| |
| |||
3547 | 3548 |
| |
3548 | 3549 |
| |
3549 | 3550 |
| |
| 3551 | + | |
3550 | 3552 |
| |
3551 | 3553 |
| |
| 3554 | + | |
3552 | 3555 |
| |
3553 | 3556 |
| |
3554 | 3557 |
| |
| |||
3664 | 3667 |
| |
3665 | 3668 |
| |
3666 | 3669 |
| |
3667 |
| - | |
| 3670 | + | |
3668 | 3671 |
| |
3669 | 3672 |
| |
3670 | 3673 |
| |
| |||
3681 | 3684 |
| |
3682 | 3685 |
| |
3683 | 3686 |
| |
3684 |
| - | |
| 3687 | + | |
3685 | 3688 |
| |
3686 | 3689 |
| |
3687 | 3690 |
| |
| |||
3759 | 3762 |
| |
3760 | 3763 |
| |
3761 | 3764 |
| |
3762 |
| - | |
| 3765 | + | |
3763 | 3766 |
| |
3764 | 3767 |
| |
3765 | 3768 |
| |
3766 | 3769 |
| |
3767 |
| - | |
| 3770 | + | |
3768 | 3771 |
| |
3769 | 3772 |
| |
3770 | 3773 |
| |
| |||
3848 | 3851 |
| |
3849 | 3852 |
| |
3850 | 3853 |
| |
3851 |
| - | |
| 3854 | + | |
3852 | 3855 |
| |
3853 | 3856 |
| |
3854 | 3857 |
| |
| |||
3887 | 3890 |
| |
3888 | 3891 |
| |
3889 | 3892 |
| |
| 3893 | + | |
3890 | 3894 |
| |
3891 | 3895 |
| |
3892 | 3896 |
| |
| |||
3895 | 3899 |
| |
3896 | 3900 |
| |
3897 | 3901 |
| |
3898 |
| - | |
| 3902 | + | |
3899 | 3903 |
| |
3900 | 3904 |
| |
3901 | 3905 |
| |
| |||
3933 | 3937 |
| |
3934 | 3938 |
| |
3935 | 3939 |
| |
3936 |
| - | |
| 3940 | + | |
3937 | 3941 |
| |
3938 | 3942 |
| |
3939 | 3943 |
| |
| |||
4050 | 4054 |
| |
4051 | 4055 |
| |
4052 | 4056 |
| |
4053 |
| - | |
| 4057 | + | |
4054 | 4058 |
| |
4055 | 4059 |
| |
4056 | 4060 |
| |
| |||
4362 | 4366 |
| |
4363 | 4367 |
| |
4364 | 4368 |
| |
4365 |
| - | |
| 4369 | + | |
4366 | 4370 |
| |
4367 | 4371 |
| |
4368 | 4372 |
| |
| |||
4586 | 4590 |
| |
4587 | 4591 |
| |
4588 | 4592 |
| |
4589 |
| - | |
4590 | 4593 |
| |
4591 | 4594 |
| |
4592 | 4595 |
| |
4593 | 4596 |
| |
4594 |
| - | |
| 4597 | + | |
4595 | 4598 |
| |
4596 | 4599 |
| |
4597 | 4600 |
| |
| |||
5177 | 5180 |
| |
5178 | 5181 |
| |
5179 | 5182 |
| |
| 5183 | + | |
5180 | 5184 |
| |
5181 | 5185 |
| |
5182 | 5186 |
| |
|
Lines changed: 3 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
229 | 229 |
| |
230 | 230 |
| |
231 | 231 |
| |
232 |
| - | |
233 |
| - | |
234 |
| - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
235 | 235 |
| |
236 | 236 |
| |
237 | 237 |
| |
|
0 commit comments
Comments
(0)