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 9324349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:34:32+00:00 2026-06-19T04:34:32+00:00

How is trigger function different from ‘regular’ functions? And is it absolutely necessary in

  • 0

How is trigger function different from ‘regular’ functions? And is it absolutely necessary in creating a trigger?

For example, in this case:

-- Trigger function
CREATE FUNCTION update_record_trigger_function() RETURNS trigger
LANGUAGE plpgsql
AS $update_record_trigger_function$
BEGIN
  PERFORM update_record(NEW.oid); -- helper function ... 
  RETURN NEW;
END
$update_record_trigger_function$;

-- Trigger for updating latest clicks for posts
CREATE TRIGGER update_latest_record
AFTER INSERT OR UPDATE ON record
FOR EACH ROW
EXECUTE PROCEDURE update_record_trigger_function();

Would it not be simpler to (or is it possible to do):

-- Trigger for updating latest clicks for posts
CREATE TRIGGER update_latest_record
AFTER INSERT OR UPDATE ON record
FOR EACH ROW
PERFORM update_record(NEW.oid); -- syntactically not right but along this idea

I wasn’t able to find any document with examples of ‘skipping trigger function’ or one that explaining how trigger function is special and necessary for triggers?

  • 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-19T04:34:34+00:00Added an answer on June 19, 2026 at 4:34 am

    PostgreSQL separates the “trigger function” from the trigger definition for quite a few reasons:

    • Trigger functions can be written as generic functions that can work on many different tables, so you can add the same trigger function as a trigger to many different tables. This eases maintenance.

    • Trigger functions can take parameters that allow them to adapt to specific column names or other characteristics of the table you apply them to. This makes it practical to write generic, re-usable trigger functions where you otherwise could not do so, so you often don’t need to repeat the code in multiple places. See EXECUTE ... USING and the format function with its %L and %I format-specifiers.

    • PostgreSQL tries very hard not care what programming language your functions are written in . They could be PL/PgSQL, Python, Perl, C, or MyWackyPluginLanguage. If it didn’t separate trigger function from trigger definition this would be harder to achieve.

    The shorthand you describe is not supported in PostgreSQL, though some other database systems provide something very much like what you’ve shown. You essentially want to be able to define a trigger function as an inline expression. This isn’t supported. There’s never been a pressing need for it so nobody’s implemented it.

    If such a feature were added in future – and I’m not aware of any plans to do so – it would probably be done using a PL/PgSQL DO block that was contextually interpreted as a trigger, something like (not legal syntax):

    CREATE TRIGGER update_latest_record
    AFTER INSERT OR UPDATE ON record
    FOR EACH ROW DO $$ PERFORM update_record(NEW.oid); RETURN NEW; $$;
    

    That way the parser wouldn’t need to understand PL/PgSQL constructs, we’d just have to teach it to understand FOR EACH ROW DO [string literal body of function] as an alternative to FOR EACH ROW EXECUTE PROCEDURE proc_name(args) and then invoke the PL/PgSQL subsystem to process the trigger literal.

    In practice Pg would probably just generate an ordinary trigger function and add a reference to it from the trigger so it’s dropped if the trigger was dropped, making this a just convenience macro, just like SERIAL is a convenience macro for an INTEGER field with a DEFAULT nextval(...) and a generated SEQUENCE owned by the table with the SERIAL field. In particular, pg_dump would probably output it as if you’d defined a separate trigger function and trigger, rather than used the shorthand.

    Honestly, I doubt anything like this will ever be added, but if you can provide sufficiently convincing use cases you might if you’re really lucky interest someone in it. Most likely you’ll only get anywhere with such a proposal (“allow DO blocks to be used as trigger procedures”) if you’re willing to back it with funding for the time required to implement the feature.

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

Sidebar

Related Questions

Given this simple example trigger: CREATE TRIGGER example_update ON example_table FOR UPDATE AS BEGIN
I'm looking for a way to trigger for a different function on each individual
I'm very new to trigger function. Actually this is the first time I'm using
When I pass 'this' to an anonymous function like so: MyClass.prototype.trigger = function(){ window.setTimeout(function(){this.onTimeout();},1000);
I ve created function and trigger as follows: CREATE OR REPLACE FUNCTION New_Ticket() RETURNS
I have this code which loads automatically a different picture from an array everytime
I am trying to trigger a function from inside my column MC via an
I need to trigger function bar() whenever function foo() fires. I have no control
I am using a trigger function to write data into a new table in
I am basically trying to trigger a function if the footer is inside the

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.