PostgreSQL-function、trigger
增加一个自动记录更新时间的触发器,
第一步,先写一个函数,返回触发器类型的
create function spam_keyword_update_trigger() returns trigger as $$ begin NEW.tm_update := current_timestamp(0); return new; end; $$ language plpgsql;
第二步,添加调用函数的触发器,在这里我把触发器名称和函数名称设为一样的
create trigger spam_keyword_update_trigger before update on spam_keyword for each row execute procedure spam_keyword_update_trigger();
了解一张表有哪些触发器
\d table_name
了解触发器所引用函数的定义
\sf function_name
了解一共有哪些自己可见的函数
\df
行类型
create or replace function thaha(ooo website)returns text as $$
declare
t2_row record;
BEGIN
select into t2_row gid from board where fid=52163;
-- RAISE EXCEPTION 'employee % not found', ooo.name;
return ooo||ooo.url||t2_row.gid;
END;
$$language plpgsql;
select thaha(website) from website where fid=52163
create or replace function funcx1() returns setof text as $$
declare
i spam_keyword.word%type;
o text ;
begin
for i in select kid from spam_keyword loop
o:=i;
return next o;
end loop;
end;
$$language plpgsql;
select funcx1()
drop function funcx1()