postgresql/src/backend/commands
Tom Lane 9b9c5f279e Clarify behavior of adding and altering a column in same ALTER command.
The behavior of something like

ALTER 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's
intentional and desirable for a couple of reasons:

* It makes the behavior the same whether you merge the sub-commands
into one ALTER command or give them separately;

* If we applied the new default while filling the table, there would
be no way to get the existing behavior in one SQL command.

The same reasoning applies in cases that add a column and then
manipulate 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 in
the referenced discussion thread I'd thought it was a bug to be
fixed).  And it certainly wasn't documented.

Hence, add documentation, code comments, and a test case to clarify
that this behavior is all intentional.

In passing, adjust ATExecAddColumn's defaults-related relkind check
so that it matches up exactly with ATRewriteTables, instead of being
effectively (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 it
did not before).

Discussion: https://postgr.es/m/10365.1558909428@sss.pgh.pa.us
2020-01-21 16:17:21 -05:00
..
aggregatecmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
alter.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
amcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
analyze.c Report progress of ANALYZE commands 2020-01-15 11:14:39 -03:00
async.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
cluster.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
collationcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
comment.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
constraint.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
conversioncmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
copy.c Fix problems with "read only query" checks, and refactor the code. 2020-01-16 12:11:31 -05:00
createas.c Make better use of ParseState in ProcessUtility 2020-01-04 13:12:41 +01:00
dbcommands.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
define.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
discard.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
dropcmds.c Revert "Forbid DROP SCHEMA on temporary namespaces" 2020-01-08 10:36:12 +09:00
event_trigger.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
explain.c Make better use of ParseState in ProcessUtility 2020-01-04 13:12:41 +01:00
extension.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
foreigncmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
functioncmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
indexcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
lockcmds.c Fix problems with "read only query" checks, and refactor the code. 2020-01-16 12:11:31 -05:00
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
matview.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
opclasscmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
operatorcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
policy.c Make parser rely more heavily on the ParseNamespaceItem data structure. 2020-01-02 11:29:01 -05:00
portalcmds.c Make better use of ParseState in ProcessUtility 2020-01-04 13:12:41 +01:00
prepare.c Make better use of ParseState in ProcessUtility 2020-01-04 13:12:41 +01:00
proclang.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
publicationcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
schemacmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
seclabel.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
sequence.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
statscmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
subscriptioncmds.c Make lsn argument of walrcv_create_slot() optional 2020-01-11 09:07:14 +01:00
tablecmds.c Clarify behavior of adding and altering a column in same ALTER command. 2020-01-21 16:17:21 -05:00
tablespace.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
trigger.c Make parser rely more heavily on the ParseNamespaceItem data structure. 2020-01-02 11:29:01 -05:00
tsearchcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
typecmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
user.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
vacuum.c Allow vacuum command to process indexes in parallel. 2020-01-20 07:57:49 +05:30
variable.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
view.c Restructure ALTER TABLE execution to fix assorted bugs. 2020-01-15 18:49:24 -05:00