postgres 在查询面板直接执行查询语句while,不再函数中定义变量,语句单独执行,就叫临时函数咯

之前一直以为while 语句只能在函数中执行,今天算是涨知识了.

DO $$
DECLARE
i INTEGER := 1;
identityId BIGINT := 200000000001;
BEGIN
  WHILE i < 100 LOOP
    identityId = identityId + 1;
  raise notice '%',i;
      -- INSERT 语句
      -- 将字符串转为 uuid cast ('057b8c51-f62f-4260-bdbb-' || identityId as uuid)
							 
    i = i + 1;
  END LOOP;
END $$;

执行execute 不用再函数中进行了:

do
$$
    begin
        execute 'insert into test_searial values (2)';
    end;
    $$
posted @ 2020-07-17 18:41  那时一个人  阅读(334)  评论(0编辑  收藏  举报