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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:05:27+00:00 2026-06-05T07:05:27+00:00

I am just started writing the PL/pgSQL Trigger function. I am having couple of

  • 0

I am just started writing the PL/pgSQL Trigger function. I am having couple of tables called Student and Result. Student having the following columns. ID,name,subject,mark (ID is the primary key) and the Result table is having two columns like ID,Status

Whenever one record has added in the student table, I want to update the Result table by checking the mark in the Student table, If the mark entered is greater than 50 then one record should be inserted in the Result table with ID and Status = Pass and if it is less than 50 then status will be fail.
I have the following Trigger function to achieve this


CREATE OR REPLACE FUNCTION "UpdateResult"() RETURNS trigger AS $BODY$
  BEGIN  
    IF NEW.mark < 50 THEN   
       INSERT INTO "Result" SELECT 92,'fail';
       RETURN NEW;
  ELSE 
 INSERT INTO "Result" SELECT 92,'pass';
 RETURN NEW;  
END IF;      
     END; 
    $BODY$
      LANGUAGE 'plpgsql' VOLATILE STRICT SECURITY DEFINER
      COST 100;
     ALTER FUNCTION "UpdateResult"() OWNER TO postgres;

CREATE TRIGGER "Result"
  AFTER INSERT
  ON "Student"
  FOR EACH ROW
  EXECUTE PROCEDURE "UpdateResult"();

By this function trigger has worked as expected since I have hard coded the primary key value.
But When I modify the SQL inside Trigger function like the following

INSERT INTO “Result” SELECT NEW.ID,’fail’; (or)
INSERT INTO “Result” SELECT NEW.ID,’pass’;

It is throwing error like

>  ***Record "new" has no field "id"   Context : PL/pgSQL function
> "UpdateResult" line 3 at SQL statement***

Means it is able to take the values of non primary key values from NEW variable not the primary key value. Can any one please tell me is there a restriction in PL/pgSQL or Am I doing anything wrong !

  • 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-05T07:05:27+00:00Added an answer on June 5, 2026 at 7:05 am

    Just a hint: why are you using quoted names? When doing this, you have to care about capitalisation.

    See if this works:

    CREATE OR REPLACE FUNCTION UpdateResult() RETURNS trigger AS $BODY$
      BEGIN  
        IF NEW.mark < 50 THEN   
           INSERT INTO result (id, status) values (92,'fail');
           RETURN NEW;
      ELSE 
           INSERT INTO result (id, status) values (92,'pass');
           RETURN NEW;  
    END IF;      
         END; 
        $BODY$
          LANGUAGE 'plpgsql' VOLATILE STRICT SECURITY DEFINER
          COST 100;
         ALTER FUNCTION UpdateResult() OWNER TO postgres;
    
    CREATE TRIGGER Result
      AFTER INSERT
      ON Student
      FOR EACH ROW
      EXECUTE PROCEDURE UpdateResult();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting started on writing functions instead of writing everything inline. Is this
I have just started learning Jquery and am new to writing javascript (I am
I have just installed C# 2008 Express Edition 2008 and started writing code. My
I've just started writing on a component where I found it might be useful
I am new to android.. just started writing service using activity.. i want to
I'm just getting started writing an app for WP (Mango), and am running into
I'm just getting started writing a simple web crawler to get info on links
I just started learning Python... I am writing a simple program that will take
I just started with Google App Engine using python and I was following a
Just started writing java / android and I am trying to use android.widget.VideoView. I

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.