How to update billions row in a Database in postgres?

91 views Asked by At

We have to use a null column to Hardcoded Value 'Yes'. Can't use simple script

update my_table
set column='Yes'
where column is Null

Since we have huge chucks of data, this isn't the way. What is the best way to update it?

1

There are 1 answers

0
Abdul Jabbar On

Instead of updating billions of rows with only field as "Yes" for every record, I would suggest you to create another lookup table and add record in it only when source record has other than "Yes" using your Primary Key from Original Table with new Lookup table.

//create table lookupTable;
CREATE TABLE lookUpTable (
    id INT AUTO_INCREMENT PRIMARY KEY,
    recordFor INT NOT NULL, //Your my_table record id 
    myText varchar(10) NOT NULL
);

Search this table against your my_table row. If the record is found in LookupTable than myText value otherwise false.