Jaya
Jaya

Reputation: 128

Replacing value of a column should not update last_modified time in PostgreSQL

I have to replace the some column value to other value but it should not update the last_modified column

id  name        last_modified
1   from    10.01.2019 08:54:08
2   from    10.01.2019 08:54:08
3   from    10.01.2019 08:54:08
4   Ami     10.01.2019 08:54:08

To

id  name        last_modified
1   to      10.01.2019 08:54:08
2   to      10.01.2019 08:54:08
3   to      10.01.2019 08:54:08
4   Ami     10.01.2019 08:54:08

Upvotes: 1

Views: 38

Answers (2)

Laurenz Albe
Laurenz Albe

Reputation: 246013

Assuming that you have a trigger on the table that sets last_modified, you could prevent its execution in two ways:

  • Disabling the trigger:

    ALTER TABLE mytable DISABLE TRIGGER modified_trig;
    

    After your update is done, re-enable it:

    ALTER TABLE mytable ENABLE TRIGGER modified_trig;
    

    To avoid concurrent data modifications while you are running your update, run both ALTER TABLEs and the update in a single transaction.

  • Make sure that (normal) triggers are not fired at all while you run your update.

    This can be done by running

    SET session_replication_role=replica;
    

    You need superuser privileges for this.

Upvotes: 2

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 32003

you can update a specific column

update table_name set name='to' where name='from'

Upvotes: 0

Related Questions