[ <<label>> ]
[ DECLARE
declarations ]
BEGIN
statements
END [ label ];
do $$
begin
raise notice '无Label标签与声明部分';
end $$;
或者
do $$
<<test>>
begin
raise notice '使用label标签';
end test $$;
或者
do $$
<<test>>
declare
i int:=1;
begin
i := i+1;
raise notice '使用label标签,声明i变量,i=%',i;
end test $$;
比较复杂的sql数据类型有
–声明字符串类型变量
name varchar(30);
–声明复合数据类型
user_info user%rowtype;
–拷贝字段的类型
user_id user.id%type;
–声明记录类型
user_list record;
do $$
<<test>>
declare
i int:=1;
t_product product%rowtype;
t_list record;
begin
select * into t_product from product where id = 1;
raise notice '客户:%,订单编号:% ',t_product.name,t_product.id;
for t_list in (select * from product) loop
raise notice '客户:%,订单编号:% ',t_list.name,t_list.id;
end loop;
end test $$;