gpt4 book ai didi

sql - Postgres 触发器创建 - 错误 : no language specified SQL state: 42P13

转载 作者:行者123 更新时间:2023-11-29 11:11:08 34 4
gpt4 key购买 nike

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

代码块:

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$

错误:

 ERROR: no language specified
SQL state: 42P13

接下来我可以尝试什么?

最佳答案

试试这个方法:

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.

关于sql - Postgres 触发器创建 - 错误 : no language specified SQL state: 42P13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39607334/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com