我在语言'plpgsql'中遇到了sql问题。sql触发器更新并插入
问题是先在客户表中添加一个新的列clean_phone。然后在插入和更新时使用触发器来将clean_phone填充到random_string()函数。这是我做的。
创建新列
alter table customers
add clean_phone varchar(15);
触发
create or replace function clean_function()
returns trigger as
$$
begin
new.clean_phone = random_string();
return new;
end;
$$
language 'plpgsql';
drop trigger clean_phone on customers;
create trigger clean_phone
before update or insert
on customers
for each row
execute procedure clean_function();
而且最终,显示表
select name,clean_phone from customers;
我的问题是在我运行的所有代码,并显示结果,clean_phone列仍然没有显示任何内容。那么,我该如何解决这个问题?
你插入或更新表中的东西吗?触发器只在这些情况下被调用。 –
我试图插入/更新任何东西,但它显示错误,说明clean_phone不存在 – youlingjun0505
错误:值变得太长,因为类型字符变化(15) SQL状态:22001 上下文:PL/pgSQL函数clean_function()第3行 – youlingjun0505