cnblogs/dcrenl/postgresql使用for循环.md
2024-09-24 12:43:01 +08:00

15 lines
377 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

开发过程中经常需要制造一些测试数据sqlserver等数据库都有循环执行语句的方式postgresql也可以使用for循环插入数据
``` sql
do $$
begin
for tt in 1..99 loop
insert into tt(id,a) values (tt,'test');
end loop;
end;
$$
```
以上语句只是简单实例可以向表中插入数据并且可以插入for循环的索引。