- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit7103ebb
committed
Add support for MERGE SQL command
MERGE performs actions that modify rows in the target table using asource table or query. MERGE provides a single SQL statement that canconditionally INSERT/UPDATE/DELETE rows -- a task that would otherwiserequire multiple PL statements. For example,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 tables, partitioned tables and inheritancehierarchies, including column and row security enforcement, as well assupport for row and statement triggers and transition tables therein.MERGE is optimized for OLTP and is parameterizable, though also usefulfor large scale ETL/ELT. MERGE is not intended to be used in preferenceto existing single SQL commands for INSERT, UPDATE or DELETE since thereis some overhead. MERGE can be used from PL/pgSQL.MERGE does not support targetting updatable views or foreign tables, andRETURNING clauses are not allowed either. These limitations are likelyfixable with sufficient effort. Rewrite rules are also not supported,but it's not clear that we'd want to support them.Author: Pavan Deolasee <pavan.deolasee@gmail.com>Author: Álvaro Herrera <alvherre@alvh.no-ip.org>Author: Amit Langote <amitlangote09@gmail.com>Author: Simon Riggs <simon.riggs@enterprisedb.com>Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>Reviewed-by: Andres Freund <andres@anarazel.de> (earlier versions)Reviewed-by: Peter Geoghegan <pg@bowt.ie> (earlier versions)Reviewed-by: Robert Haas <robertmhaas@gmail.com> (earlier versions)Reviewed-by: Japin Li <japinli@hotmail.com>Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com>Reviewed-by: Zhihong Yu <zyu@yugabyte.com>Discussion:https://postgr.es/m/CANP8+jKitBSrB7oTgT9CY2i1ObfOt36z0XMraQc+Xrz8QB0nXA@mail.gmail.comDiscussion:https://postgr.es/m/CAH2-WzkJdBuxj9PO=2QaO9-3h3xGbQPZ34kJH=HukRekwM-GZg@mail.gmail.comDiscussion:https://postgr.es/m/20201231134736.GA25392@alvherre.pgsql1 parentae63017 commit7103ebb
File tree
95 files changed
+8726
-167
lines changed- contrib/test_decoding
- expected
- sql
- doc/src/sgml
- ref
- src
- backend
- catalog
- commands
- executor
- nodes
- optimizer
- plan
- prep
- util
- parser
- rewrite
- tcop
- utils/adt
- bin/psql
- include
- commands
- executor
- nodes
- optimizer
- parser
- tcop
- interfaces/libpq
- pl/plpgsql/src
- test
- isolation
- expected
- specs
- 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.
95 files changed
+8726
-167
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 | |
---|---|---|---|
| |||
4125 | 4125 |
| |
4126 | 4126 |
| |
4127 | 4127 |
| |
4128 |
| - | |
4129 |
| - | |
4130 |
| - | |
| 4128 | + | |
| 4129 | + | |
| 4130 | + | |
| 4131 | + | |
| 4132 | + | |
4131 | 4133 |
| |
4132 | 4134 |
| |
4133 | 4135 |
| |
|
Lines changed: 33 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 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
425 | 456 |
| |
426 | 457 |
| |
427 | 458 |
| |
| |||
924 | 955 |
| |
925 | 956 |
| |
926 | 957 |
| |
927 |
| - | |
| 958 | + | |
| 959 | + | |
928 | 960 |
| |
929 | 961 |
| |
930 | 962 |
| |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1388 | 1388 |
| |
1389 | 1389 |
| |
1390 | 1390 |
| |
1391 |
| - | |
| 1391 | + | |
1392 | 1392 |
| |
1393 | 1393 |
| |
1394 | 1394 |
| |
| |||
1666 | 1666 |
| |
1667 | 1667 |
| |
1668 | 1668 |
| |
1669 |
| - | |
| 1669 | + | |
| 1670 | + | |
1670 | 1671 |
| |
1671 | 1672 |
| |
1672 | 1673 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
158 | 158 |
| |
159 | 159 |
| |
160 | 160 |
| |
| 161 | + | |
161 | 162 |
| |
162 | 163 |
| |
163 | 164 |
| |
|
Lines changed: 18 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
55 | 55 |
| |
56 | 56 |
| |
57 | 57 |
| |
58 |
| - | |
| 58 | + | |
| 59 | + | |
59 | 60 |
| |
60 | 61 |
| |
61 | 62 |
| |
| |||
281 | 282 |
| |
282 | 283 |
| |
283 | 284 |
| |
284 |
| - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
285 | 288 |
| |
286 | 289 |
| |
287 | 290 |
| |
| |||
305 | 308 |
| |
306 | 309 |
| |
307 | 310 |
| |
308 |
| - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
309 | 314 |
| |
310 | 315 |
| |
311 | 316 |
| |
| |||
435 | 440 |
| |
436 | 441 |
| |
437 | 442 |
| |
438 |
| - | |
| 443 | + | |
439 | 444 |
| |
440 | 445 |
| |
441 | 446 |
| |
| |||
459 | 464 |
| |
460 | 465 |
| |
461 | 466 |
| |
462 |
| - | |
| 467 | + | |
463 | 468 |
| |
464 | 469 |
| |
465 | 470 |
| |
| |||
613 | 618 |
| |
614 | 619 |
| |
615 | 620 |
| |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
616 | 629 |
| |
617 | 630 |
| |
618 | 631 |
| |
|
Lines changed: 10 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
589 | 589 |
| |
590 | 590 |
| |
591 | 591 |
| |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
592 | 599 |
| |
593 | 600 |
| |
594 | 601 |
| |
| |||
759 | 766 |
| |
760 | 767 |
| |
761 | 768 |
| |
762 |
| - | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
763 | 772 |
| |
764 | 773 |
| |
765 | 774 |
| |
|
0 commit comments
Comments
(0)