Re: PL/pgSQL support to define multi variables once

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: PL/pgSQL support to define multi variables once
Дата
Msg-id 20140613153943.GM18688@eldon.alvh.no-ip.org
обсуждение исходный текст
Ответ на PL/pgSQL support to define multi variables once  (Quan Zongliang <quanzongliang@gmail.com>)
Список pgsql-hackers
Quan Zongliang wrote:
> Hi all,
> 
> Please find the attachment.
> 
> By my friend asking, for convenience,
> support to define multi variables in single PL/pgSQL line.
> 
> Like this:
> 
> CREATE OR REPLACE FUNCTION try_mutlivardef() RETURNS text AS $$
> DECLARE
> local_a, local_b, local_c text := 'a1----';
> BEGIN
> return local_a || local_b || local_c;
> end;
> $$ LANGUAGE plpgsql;

This seems pretty odd.  I think if you were to state it like this:

create or replace function multivar() returns text language plpgsql as $$
declarea, b, c text;
begina := b := c := 'a1--';return a || b || c;
end;
$$;

it would make more sense to me.  There are two changes to current
behavior in that snippet; one is the ability to declare several
variables in one go (right now you need one declaration for each), and
the other is that assignment is an expression that evaluates to the
assigned value, so you can assign that to another variable.

Personally, in C I don't think I do this:int a, b;
but always "int a; int b;" (two lines of course).  This is matter of
personal taste, but it seems clearer to me.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services



В списке pgsql-hackers по дате отправления:

Предыдущее
От: "David E. Wheeler"
Дата:
Сообщение: Re: make check For Extensions
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: PL/pgSQL support to define multi variables once