我正在尝试创建一个event trigger
, 每当创建表时执行。发生这种情况时,我想插入一个表(它有 2 列id
和tablename
)创建的表的名称。阅读文档我无法找到如何获取表名。
到目前为止,我有这个:
CREATE OR REPLACE FUNCTION insert_layer()
RETURNS event_trigger
AS $$
DECLARE r RECORD;
BEGIN
RAISE NOTICE 'event for % ', tg_tag;
-- I would like to execute this
--EXECUTE format('INSERT INTO "public.Layers"(name) VALUES(' || tableNameHere || ')') INTO result;
END;
$$
LANGUAGE plpgsql;
CREATE EVENT TRIGGER insert_layer_event ON ddl_command_start
WHEN TAG IN ('CREATE TABLE')
EXECUTE PROCEDURE insert_layer();