在plpgsql中声明多个相同类型的变量有什么捷径吗?

Is there any shortcut to declare several variables of the same type in plpgsql?

目前我是这样声明所有变量的:

declare
  x int;
  y int;
  z int;
begin
  ...
end

是否可以在一行中声明 xyz(它们具有相同的类型),例如:

declare
  x, y, z int;
begin
  ...
end

到目前为止我在 the documentation 中没有发现任何提示...

没有这种语法快捷方式。

几乎不需要这个,因为 PL/pgSQL 并不意味着需要很多变量。过多的变量表示滥用语言,最好用作 SQL 语句的粘合剂。

要声明多个相同类型的变量,您可以显式声明第一个,然后使用 variable%TYPE 复制其余变量的类型。参见:

DO
$func$
DECLARE
   x int;
   y x%TYPE;
   z x%TYPE;
BEGIN
   RAISE NOTICE 'type of x: %; type of y: %; type of z: %'
              , pg_typeof(x), pg_typeof(y), pg_typeof(z);
END
$func$

如果你的问题是关于一行(我不这么认为),你可以这样做,但每个都有它的类型:

   x int; y int; z int;

或者您可以使用数组类型来保存任意数量的相同类型,或任意类型的行或记录类型...