Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 164657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:46:58+00:00 2026-05-11T11:46:58+00:00

How to prevent recursive execution of trigger? Let’s say I want to construct a

  • 0

How to prevent recursive execution of trigger? Let’s say I want to construct a ‘tree-able’ description on chart of account. So what I do is when a new record is inserted/updated, I update the the parent record’s down_qty, so this would trigger the update trigger recursively.

Right now, my code is ok – I put this on UPDATE trigger’s first line:

-- prevents recursive trigger if new.track_recursive_trigger <> old.track_recursive_trigger then     return new; end if; 

And this is the sample code from my trigger when I need to update the parent record’s qty:

update account_category set      track_recursive_trigger = track_recursive_trigger + 1, -- i put this line to prevent recursive trigger     down_qty = down_qty - (old.down_qty + 1) where account_category_id = m_parent_account; 

I’m thinking if there’s a way in PostgreSQL to detect recursive trigger without introducing a new field, something analogous to MSSQL’s trigger_nestlevel.

[EDIT]

I loop inside the tree, I need to bubble up the down_qty of each account_category back to its root. For example, I insert a new account category, it needs to increment the down_qty of its parent account_category, likewise when I change the account category’s parent account_category, I need to decrement the down_qty of account_category‘s previous parent account_category. Though I think it can, I’m not letting PostgreSQL do the recursive trigger. I used MSSQL before where the trigger recursive depth level is limited only up to 16 levels.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:46:59+00:00Added an answer on May 11, 2026 at 11:46 am

    In pg, it’s up to you to track trigger recursion.

    If a trigger function executes SQL commands then these commands might fire triggers again. This is known as cascading triggers. There is no direct limitation on the number of cascade levels. It is possible for cascades to cause a recursive invocation of the same trigger; for example, an INSERT trigger might execute a command that inserts an additional row into the same table, causing the INSERT trigger to be fired again. It is the trigger programmer’s responsibility to avoid infinite recursion in such scenarios.

    https://www.postgresql.org/docs/13/trigger-definition.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 220k
  • Answers 220k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think for what you want to do, the best… May 13, 2026 at 12:01 am
  • Editorial Team
    Editorial Team added an answer You don't have the Ruby SSL support installed, causing Rails… May 13, 2026 at 12:01 am
  • Editorial Team
    Editorial Team added an answer There is an NSApplication delegate protocol method you can implement.… May 13, 2026 at 12:01 am

Related Questions

How to prevent recursive execution of trigger? Let's say I want to construct a
I would like to either prevent or handle a StackOverflowException that I am getting
Given a model with ForeignKeyField (FKF) or ManyToManyField (MTMF) fields with a foreignkey to
I've written an experimental function evaluator that allows me to bind simple functions together
Does anyone know how to avoid merging certain files in a branch merge? For

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.