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

  • Home
  • SEARCH
  • 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 8929687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:43:35+00:00 2026-06-15T08:43:35+00:00

I am new to Postgres (9.0.5) and have written very few functions/triggers in general.

  • 0

I am new to Postgres (9.0.5) and have written very few functions/triggers in general. I would like to set up a trigger on my widgets table such that every time a widget is inserted, updated or deleted, the entire record is passed to a stored procedure as an argument. The procedure can then inspect the record for various changes and decide what action to take. Here’s my best attempt so far, though I know I’m way off course:

CREATE OR REPLACE TRIGGER tg_widgets
ON TABLE widgets
AFTER EVERY INSERT, UPDATED, DELETE
DO run_widget_handler

CREATE OR REPLACE PROCEDURE run_widget_handler AS
    # Definitition here
    # If the widget's name was changed, do X
    # Else if the widget's wow_factor was changed, do Y
    # Else, do Z

I’m not worried about how to implement the definition of run_widget_handler, just looking for help and writing the trigger and passing the widget to the proc. Thanks in advance.

  • 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. Editorial Team
    Editorial Team
    2026-06-15T08:43:36+00:00Added an answer on June 15, 2026 at 8:43 am

    You don’t need to “pass” the row to the trigger function (btw: there is no “procedure” in PostgreSQL, only functions).

    If the function is declared as “returns trigger”, you can automatically access the complete row as “new” or “old”.

    More details in the manual: http://www.postgresql.org/docs/current/static/plpgsql-trigger.html

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

Sidebar

Related Questions

I have a peculiar problem with Postgres and PHP . I just set-up new
I am very new to Postgres and the main problem I have now is
I have a php script to insert new parts into a postgres database. I
I have an issue, I'm trying to insert a new row into a postgres
I am using Django with Postgres and Heroku. and I have a post table
I access a a postgres table using SQLAlchemy. I want a query to have
I have a postgres database with a datetime field. I'd like to permanently convert
I'm new to conditional statements within postgres. I have the following statement SELECT IF
I have a query like the following: Select new mypackage.MyClass( u, max(sc.serviceDate)) from Unit
I have some tables in my postgres database, and a few of them inherit

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.