Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Unanswered: Novice here! Quick question

    Hey guys,
    I'm a novice to postgresql and I'm working on a database for my shop. Basically every time an order is place I want my table of shoes to check if what is left in the inventory is greater than the threshold. Once what is left in stock is lower than the threshold a trigger should occur which will with the help of a trigger function enter a row in a must_order table to place an order. However I get two kinds of errors. First here is my trigger


    CREATE TRIGGER placer
    BEFORE INSERT OR UPDATE
    ON orders
    FOR EACH ROW
    EXECUTE PROCEDURE place_order();


    Now when I use this trigger function
    CREATE or REPLACE FUNCTION place_order() RETURNS trigger AS $$ BEGIN if new.quantity<new.limit THEN Insert into must_order values ('2012-10-31', default, 200); END IF;return new; END $$ LANGUAGE plpgsql;
    and try to insert into orders I get
    ERROR: record "new" has no field "quantity"
    CONTEXT: PL/pgSQL function "place_order" line 1 at IF
    (shoes table has quantity and limit columns)

    When I use this trigger function

    CREATE or REPLACE FUNCTION place_order() RETURNS trigger AS $$ BEGIN if shoes.quantity<shoes.limit THEN Insert into must_order values ('2012-10-31', default, 200); END IF; END $$ LANGUAGE plpgsql;

    and try to insert an order I get this error

    SELECT shoes.quantity<shoes.limit
    CONTEXT: PL/pgSQL function "place_order" line 1 at IF

    Don't really know what is going on. Can someone help me please ?

  2. #2
    Join Date
    Nov 2012
    Posts
    2
    Nevermind solved it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •