Raising error in postgreSQL

前端 未结 3 1286
無奈伤痛
無奈伤痛 2021-02-20 03:45
CREATE OR REPLACE FUNCTION msgfailerror() RETURNS trigger AS 
\' BEGIN 
    IF NEW.noces< new.first_column THEN 
        RAISE EXCEPTION \'cannot have a negative sala         


        
3条回答
  •  遇见更好的自我
    2021-02-20 04:14

    The quoting is wrong. It's easier to use dollar quotes $$:

    CREATE OR REPLACE FUNCTION msgfailerror() 
    RETURNS trigger AS 
    $$
    BEGIN 
      IF NEW.noces< new.first_column THEN 
        RAISE EXCEPTION 'cannot have a negative salary'; 
      END IF; 
      return new; 
    END;
    $$
    LANGUAGE plpgsql;
    

    But on the other hand, what's wrong with a check constraint?

提交回复
热议问题