Skip to content

Trigger for Update #2046

Answered by wolfgangwalther
praj18 asked this question in Q&A
Nov 25, 2021 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

I see 3 approaches to solve that:

  1. Use a MATERIALIZED VIEW to aggregate the data. Then refresh that CONCURRENTLY periodically. This means, that the total numbers of reactions might not always be accurate immediately. In the future, incremental view maintenance might be implemented in PG, which would solve that.

  2. Use the trigger approach, but aggregate the full post_reaction row after each insert/update/delete to reactions.

  3. Use the trigger approach and create the UPDATE statement you're using right now via dynamic SQL. In this case you don't need all the IF conditions.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@praj18
Comment options

@wolfgangwalther
Comment options

@praj18
Comment options

Answer selected by praj18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants