Detecting column changes in a postgres update trigger

后端 未结 3 385
清歌不尽
清歌不尽 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 05:41

    http://www.postgresql.org/docs/9.3/static/plpython-trigger.html

    TD["table_name"]
    

    I do exactly the same type of notify, I loop through all of the columns like this:

        for k in TD["new"]:
            if TD["old"][k] != TD["new"][k]:
                changed.append(k)
    

    changed.append(k) builds my notification string. Somewhere else I do a listen, then broadcast the results out pub/sub to web socket clients.

    -g

提交回复
热议问题