forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit9b9c5f2
committed
Clarify behavior of adding and altering a column in same ALTER command.
The behavior of something likeALTER TABLE transactions ADD COLUMN status varchar(30) DEFAULT 'old', ALTER COLUMN status SET default 'current';is to fill existing table rows with 'old', not 'current'. That'sintentional and desirable for a couple of reasons:* It makes the behavior the same whether you merge the sub-commandsinto one ALTER command or give them separately;* If we applied the new default while filling the table, there wouldbe no way to get the existing behavior in one SQL command.The same reasoning applies in cases that add a column and thenmanipulate its GENERATED/IDENTITY status in a second sub-command,since the generation expression is really just a kind of default.However, that wasn't very obvious (at least not to me; earlier inthe referenced discussion thread I'd thought it was a bug to befixed). And it certainly wasn't documented.Hence, add documentation, code comments, and a test case to clarifythat this behavior is all intentional.In passing, adjust ATExecAddColumn's defaults-related relkind checkso that it matches up exactly with ATRewriteTables, instead of beingeffectively (though not literally) the negated inverse condition.The reasoning can be explained a lot more concisely that way, too(not to mention that the comment now matches the code, which itdid not before).Discussion:https://postgr.es/m/10365.1558909428@sss.pgh.pa.us1 parentaffdde2 commit9b9c5f2
File tree
4 files changed
+59
-12
lines changed- doc/src/sgml/ref
- src
- backend/commands
- test/regress
- expected
- sql
4 files changed
+59
-12
lines changedLines changed: 35 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
203 | 203 |
| |
204 | 204 |
| |
205 | 205 |
| |
206 |
| - | |
207 |
| - | |
208 |
| - | |
209 |
| - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
210 | 211 |
| |
211 | 212 |
| |
212 | 213 |
| |
| |||
268 | 269 |
| |
269 | 270 |
| |
270 | 271 |
| |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
271 | 276 |
| |
272 | 277 |
| |
273 | 278 |
| |
| |||
1370 | 1375 |
| |
1371 | 1376 |
| |
1372 | 1377 |
| |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
1373 | 1404 |
| |
1374 | 1405 |
| |
1375 | 1406 |
| |
|
Lines changed: 12 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6126 | 6126 |
| |
6127 | 6127 |
| |
6128 | 6128 |
| |
6129 |
| - | |
6130 |
| - | |
6131 |
| - | |
6132 |
| - | |
6133 |
| - | |
6134 |
| - | |
6135 |
| - | |
6136 |
| - | |
| 6129 | + | |
| 6130 | + | |
| 6131 | + | |
| 6132 | + | |
| 6133 | + | |
| 6134 | + | |
| 6135 | + | |
| 6136 | + | |
| 6137 | + | |
| 6138 | + | |
| 6139 | + | |
| 6140 | + | |
6137 | 6141 |
| |
6138 | 6142 |
| |
6139 | 6143 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
409 | 409 |
| |
410 | 410 |
| |
411 | 411 |
| |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
412 | 418 |
| |
413 | 419 |
| |
414 | 420 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
269 | 269 |
| |
270 | 270 |
| |
271 | 271 |
| |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
272 | 278 |
| |
273 | 279 |
| |
274 | 280 |
| |
|
0 commit comments
Comments
(0)