Detecting column changes in a postgres update trigger

后端 未结 3 360
清歌不尽
清歌不尽 2021-01-12 05:34

I have a postgres database with several tables that I want to watch for updates on, and if there\'s any updates, I want to fire a \"hey, something changed\" update. This wor

3条回答
  •  北海茫月
    2021-01-12 06:02

    Read up on the hstore extension. In particular you can create a hstore from a row, which means you can do something like:

    changes := hstore(NEW) - hstore(OLD);
    ...pg_notify(... changes::text ...)
    

    That's slightly more information than you wanted (includes new values). You can use akeys(changed) if you just want the keys.

提交回复
热议问题