我在想是否可以创建一个带有参数的触发器函数,因为函数的逻辑是相同的,但可能只是插入到不同的表和列名中。
以下是该函数内容:
以下是该函数内容:
CREATE OR REPLACE FUNCTION
createInstance(table_name TEXT, column_name TEXT)
RETURNS TRIGGER AS
$BODY$
BEGIN
INSERT INTO
table_name
(
column_name,
account_id
)
VALUES
(
new._id,
new.account_id
);
RETURN new;
END;
$BODY$
language plpgsql;
错误:
ERROR: trigger functions cannot have declared arguments
HINT: The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead.
CONTEXT: compilation of PL/pgSQL function "createinstance" near line 1
示例触发器:
CREATE TRIGGER trig_instanced_item_copy
AFTER INSERT ON creator.items
FOR EACH ROW
EXECUTE PROCEDURE createInstance();
TG_ARGV
,能否给出一个示例? - A. L