postgresql postgres 触发器创建 - 错误:未指定语言 SQL 状态:42P13

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39607334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:23:48  来源:igfitidea点击:

postgres trigger creation - ERROR: no language specified SQL state: 42P13

sqlpostgresql

提问by Sumon Bappi

I am new to trigger. I am trying to create a trigger by following this link - http://www.postgresqltutorial.com/creating-first-trigger-postgresql/. But it gives some error. The code block and the error is given below ::

我是新手。我正在尝试按照此链接创建触发器 - http://www.postgresqltutorial.com/creating-first-trigger-postgresql/。但它给出了一些错误。代码块和错误如下:

code block >>

代码块 >>

    CREATE OR REPLACE FUNCTION log_last_name_changes()
  RETURNS trigger AS
$BODY$
BEGIN
 IF NEW.last_name <> OLD.last_name THEN
 INSERT INTO employee_audits(employee_id,last_name,changed_on)
 VALUES(OLD.id,OLD.last_name,now());
 END IF;

 RETURN NEW;
END;
$BODY$

And the error >>

和错误>>

 ERROR: no language specified
SQL state: 42P13

Can anyone help me please ?

有人可以帮我吗?

回答by chalitha geekiyanage

Try this way:

试试这个方法:

CREATE OR REPLACE FUNCTION log_last_name_changes()
RETURNS trigger AS
$BODY$
BEGIN
IF NEW.last_name <> OLD.last_name THEN
INSERT INTO employee_audits(employee_id,last_name,changed_on)
VALUES(OLD.id,OLD.last_name,now());
END IF;

RETURN NEW;
END;
$BODY$

LANGUAGE plpgsql VOLATILE -- Says the function is implemented in the plpgsql language; VOLATILE says the function has side effects.
COST 100; -- Estimated execution cost of the function.