Behaviour adding a column with and without a default (prior to PG11)

From: Joe Horsnell <Joe(at)bambooloans(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Behaviour adding a column with and without a default (prior to PG11)
Date: 2019-09-30 20:02:47
Message-ID: 88D6C2B1-1346-45A5-AC08-37C52D75DD83@bambooloans.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

The documentation (https://www.postgresql.org/docs/10/ddl-alter.html) clearly states that adding a column with a default requires updating all the rows in the table, to store the new column value (this is prior to PG11, obviously).

I can understand why this behaviour was required when adding a not null column, but for a nullable column, it also seems reasonable to me that existing rows would not be updated and the default added to apply to new rows only.

Obviously the desired effect of adding the column default without rewriting all the rows in the table can be achieved by adding the nullable column first with no default, then changing the default, but out of curiosity; was there a specific technical reason for the behaviour described above, or was it a conscious design choice?

Many thanks,

Joe.

[Bamboo Limited | 1st Floor | Grenville House | Nelson Gate | Southampton | SO15 1GX ::: www.bambooloans.com]
This email message is intended only for the addressee(s) and contains information that may be confidential and/or copyright. If you are not the intended recipient please notify the sender by reply email and immediately delete this email. Use, disclosure or reproduction of this email by anyone other than the intended recipient(s) is strictly prohibited. Although, all emails are scanned for viruses, no representation is made that this email or any attachments are free of viruses. Virus scanning is recommended and is the responsibility of the recipient.
Help protect our environment by only printing this email if absolutely necessary.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-09-30 20:25:36 Re: Possible bug: SQL function parameter in window frame definition
Previous Message Shital A 2019-09-30 19:39:43 Need help : pgsql HA issues