-- 1.创建测试表t_user
create table if not exists t_user(
id serial primary key,
user_name varchar(255),
pass_word varchar(255),
create_time date,
dr char(1)
)
-- 2.注释
comment on column t_user.id is '测试表';
comment on column t_user.user_name is '账号';
comment on column t_user.pass_word is '密码';
comment on column t_user.create_time is '创建日期';
comment on column t_user.dr is 'delete remark';
2.测试4种不同的批量插入测试数据效率
创建存储过程
-- 创建存储过程插入数据
create or replace function batch_insert_proc(num int) returns void as
$$
begin
while num > 0 loop
insert into t_user(user_name,pass_word,create_time,dr) values('username'||round(random()*num),'password'||round(random()*num),now(),0);
num = num -1;
end loop;
exception
when others then
raise exception'(%)',SQLERRM;
end;
$$ language plpgsql;