更新postgres SQL中的错误

时间:2016-06-22 21:48:04

标签: sql postgresql

CREATE TRIGGER INSERT_salesorderdetail
before insert on salesorderdetail
for each row 
UPDATE customer
set number_of_items=IFNULL(number_of_items,0)+1
where new.customerid=customer.customerid;

我有2个表salesorderdetail和客户,我希望每次我在salesorderdetail中插入一个新项目来更新我在客户的columne number_of_items但由于某种原因我在更新时遇到语法错误。

1 个答案:

答案 0 :(得分:0)

这可能会对您有所帮助:

CREATE OR REPLACE FUNCTION update_customer()
  RETURNS trigger AS
$BODY$

  -- update ur table here

        RETURN NULL;
    END; 
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION update_customer()
  OWNER TO db_name;

现在创建触发器:

CREATE TRIGGER INSERT_salesorderdetail
before insert on salesorderdetail
for each row execute procedure update_customer();