Re: Using a TRIGGER with window functions. - Mailing list pgsql-general

From Michael Lewis
Subject Re: Using a TRIGGER with window functions.
Date
Msg-id CAHOFxGp8vGf8B9+hb37gakfHb-8TjTpfa6wCFr3vL6zrQEfQ+g@mail.gmail.com
Whole thread Raw
In response to Using a TRIGGER with window functions.  (Pól Ua Laoínecháin <linehanp@tcd.ie>)
Responses Re: Using a TRIGGER with window functions.
List pgsql-general
If you want to update many rows after updating N rows, you want an after STATEMENT trigger which is executed after insert, update or delete. You also want to ensure that only that function maintains sort_order field and that you don't update recursively, perhaps by executing that function when NEW.sort_order IS NOT DISTINCT FROM old.sort_order to prevent an infinite loop, and executing a different function when NEW.sort_order IS DISTINCT FROM OLD.sort_order such that you ensure all other fields have not changed.

By the way, your window function could be row_number() - 1 instead of activity_id - FIRST_VALUE(activity_id).

pgsql-general by date:

Previous
From: Andy Hall
Date:
Subject: Re: postgres disconnects on master after setting up replication
Next
From: "David G. Johnston"
Date:
Subject: Re: Using a TRIGGER with window functions.