mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-26 23:47:20 +02:00
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 |
||
---|---|---|
.. | ||
aggregatecmds.c | ||
alter.c | ||
amcmds.c | ||
analyze.c | ||
async.c | ||
cluster.c | ||
collationcmds.c | ||
comment.c | ||
constraint.c | ||
conversioncmds.c | ||
copy.c | ||
createas.c | ||
dbcommands.c | ||
define.c | ||
discard.c | ||
dropcmds.c | ||
event_trigger.c | ||
explain.c | ||
extension.c | ||
foreigncmds.c | ||
functioncmds.c | ||
indexcmds.c | ||
lockcmds.c | ||
Makefile | ||
matview.c | ||
opclasscmds.c | ||
operatorcmds.c | ||
policy.c | ||
portalcmds.c | ||
prepare.c | ||
proclang.c | ||
publicationcmds.c | ||
schemacmds.c | ||
seclabel.c | ||
sequence.c | ||
statscmds.c | ||
subscriptioncmds.c | ||
tablecmds.c | ||
tablespace.c | ||
trigger.c | ||
tsearchcmds.c | ||
typecmds.c | ||
user.c | ||
vacuum.c | ||
variable.c | ||
view.c |