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;
    $$
原文地址:https://www.cnblogs.com/qianxunman/p/13332167.html