Re: Adding New Column with default value. - Mailing list pgsql-admin

From Ron Johnson
Subject Re: Adding New Column with default value.
Date
Msg-id CANzqJaDDCNoLq1E5ZvebwgehN=kFmfsH0f0hmi7tBjwGJR2GTg@mail.gmail.com
Whole thread Raw
In response to Adding New Column with default value.  (Gambhir Singh <gambhir.singh05@gmail.com>)
List pgsql-admin
On Mon, Apr 28, 2025 at 1:25 PM Gambhir Singh <gambhir.singh05@gmail.com> wrote:

I got  request from app Team to  add new column to a table with following specifications

1. With Not Null Constraint
2. With Default value 0

Row Count - 50 Billion

Please help me to understand
  a. DDL statement (alter table add column) will be followed by the DML statement (Update)....Am I correct ?

Do you want existing rows to have a value of 0, or just new ones?
 
  b. What would be size of the Table (I assuming it will be doubled)

It will double if the table currently only has one scalar column.
 
  c. What is the best approach for this kind of activity.

The ALTER TABLE documentation is pretty long, but searching it for "update", and reading carefully gives pointers.

--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!

pgsql-admin by date:

Previous
From: Gambhir Singh
Date:
Subject: Adding New Column with default value.
Next
From: "David G. Johnston"
Date:
Subject: Re: Adding New Column with default value.