Re: Postgres Updating only changed columns against entire row

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Debraj Manna <subharaj(dot)manna(at)gmail(dot)com>
Cc: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Postgres Updating only changed columns against entire row
Date: 2022-07-29 12:26:44
Message-ID: CAKFQuwbkiGUnX8RxQuQRwfYSGXBT5NuhJhsEwJDx3wZcG8_LMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Thursday, July 28, 2022, Debraj Manna <subharaj(dot)manna(at)gmail(dot)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.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Mladen Gogala 2022-07-29 13:12:45 Re: Oracle data to PG
Previous Message Holger Jakobs 2022-07-29 10:38:47 Re: pg 12 \if unwanted message