PostgreSQL操作rowtype类型(赋值、插入)

CREATE OR REPLACE FUNCTION create_new_stu()
  RETURNS trigger AS
$BODY$
declare
usrid int;
student students%rowtype;
begin
usrid := NEW.id;
select * from students where sno='111' into student;
student.sname := 'zxh';
if student.cno is NULL then
	student.scid := 1;
end if;
insert into students select student.*;

return NEW;

end;

$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION create_new_stu()
  OWNER TO postgres;

rowtype类型的变量可以看作一个结构体,可以通过点访问符来获取或修改某个字段的值。将某个rowtype类型的变量值直接插入到某个结构相同的表中:

insert into students select student.*;


你可能感兴趣的:(数据库)