Postgres Updating only changed columns against entire row

From: Debraj Manna <subharaj(dot)manna(at)gmail(dot)com>
To: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Postgres Updating only changed columns against entire row
Date: 2022-07-29 06:19:55
Message-ID: CAF6DVKMGLnWB4tzWduQXXR8vtyu1DFGi9nh3u++szWZJsvSPTQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Let's say I have a table like below

CREATE TABLE empl(
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
address VARCHAR NOT NULL,
status int NOT NULL,
metadata varchar NOT NULL
);

and it has data like

(2, 'tuk', 'ind', 1, 'meta')
...
(200, 'tuka', 'eng', 2, 'meta2')

1. update empl set status = 2 where (id = 2);
2. update empl set status = 2, name='tuk', address='ind',
metadata='meta' where (id = 2);

Can someone let me know if there are any advantages of doing #1 over #2
assuming there are no other indices or triggers on the table? Which is
generally preferred?

Postgres Version - 10.17

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Ron 2022-07-29 06:32:53 Re: Postgres Updating only changed columns against entire row
Previous Message Ron 2022-07-28 17:41:41 Re: What to watch out for when ALTERing NUMERIC(38,0) to BIGINT?