Re: Postgres Updating only changed columns against entire row - Mailing list pgsql-admin

From David G. Johnston
Subject Re: Postgres Updating only changed columns against entire row
Date
Msg-id CAKFQuwbkiGUnX8RxQuQRwfYSGXBT5NuhJhsEwJDx3wZcG8_LMQ@mail.gmail.com
Whole thread Raw
In response to Postgres Updating only changed columns against entire row  (Debraj Manna <subharaj.manna@gmail.com>)
List pgsql-admin
On Thursday, July 28, 2022, Debraj Manna <subharaj.manna@gmail.com> wrote:

  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?

Neither…

You’d write:  update empl set status = $1, name = $2, … where id = $N;

Then assign some variables in your code to $1, $2, etc…

By having a parameter for each field one query can deal with changes to any of the data elements.

 

Postgres Version - 10.17


That doesn’t seem relevant, this is a theory question. 

David J.

pgsql-admin by date:

Previous
From: Holger Jakobs
Date:
Subject: Re: pg 12 \if unwanted message
Next
From: Mladen Gogala
Date:
Subject: Re: Oracle data to PG