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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:30:11+00:00 2026-06-14T05:30:11+00:00

CREATE FUNCTION update_status() RETURNS TRIGGER AS ‘ BEGIN SELECT status FROM animals IF status

  • 0
CREATE FUNCTION update_status() RETURNS TRIGGER AS ' 
BEGIN 
SELECT status FROM animals
IF status = "Alive" 
THEN 
UPDATE animals SET status = "Sold" WHERE status="Alive";   
END IF;   
RETURN NULL; 
END; ' LANGUAGE plpgsql;  

CREATE TRIGGER updatetrigger AFTER UPDATE OF id_selling ON animals EXECUTE PROCEDURE     update_status(); 

It says I’m not using the selected attributes, and I should use Perform instead of Select. But then it doesnt recognize the IF after the perform. I’m really new to these syntax, so it might be wrong. I think its clear what I want to do (and i believe it simple for someone with experience). Can you please help me with this problem?

  • 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-14T05:30:12+00:00Added an answer on June 14, 2026 at 5:30 am

    In standard SQL (and PostgreSQL), this is a quoted identifier (table name, column name, …):

    "Alive"
    

    and this is a string literal:

    'Alive'
    

    You will be getting complaints about “unknown columns” because you’re using the wrong quotes for your strings.

    Functions are usually defined with dollar-quoting to avoid this sort of thing:

    CREATE FUNCTION update_status() RETURNS TRIGGER AS $$
    BEGIN 
        SELECT status FROM animals
        IF status = 'Alive' THEN 
            UPDATE animals SET status = 'Sold' WHERE status = 'Alive';   
        END IF;   
        RETURN NULL; 
    END;
    $$ LANGUAGE plpgsql;
    

    Triggers have access to NEW and OLD to represent the previous/current state of the row and the new/updated state of the row, you should be consulting those instead of trying to SELECT to find the status:

    CREATE FUNCTION update_status() RETURNS TRIGGER AS $$
    BEGIN 
        IF NEW.status = 'Alive' THEN 
            UPDATE animals SET status = 'Sold' WHERE status = 'Alive';   
        END IF;   
        RETURN NULL; 
    END;
    $$ LANGUAGE plpgsql;
    

    You might want a little more in the WHERE clause for that UPDATE too, just WHERE status = 'Alive' seems a bit broad.

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

Sidebar

Related Questions

I using pgsql to set a trigger, when update the table dataset(change the status
How can I create an update function in javascript/jquery? An update function is a
I have this function to create a request to another file to update the
CREATE FUNCTION [dbo].[MSG_FilterAutoship] ( @ItemID VARCHAR(50) = NULL ) RETURNS @Autoship TABLE ( DistID
I have the function which gets ID and returns date from table if it
How do I create PL/SQL function which waits for update on some row for
I am trying to create a function that updates another value, and initially (after
I can create function pointers in Fortran 90, with code like real, external ::
I already managed to create function which checks if user is using a trial/demo
I have the following function: CREATE FUNCTION [dbo].[ListStockBySubCategory] ( @CategoryID varchar(10), @SubCategoryID varchar(10), @startRowIndex

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.