Re: PL/pgSQL support to define multi variables once - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: PL/pgSQL support to define multi variables once
Date
Msg-id 20140613153943.GM18688@eldon.alvh.no-ip.org
Whole thread Raw
In response to PL/pgSQL support to define multi variables once  (Quan Zongliang <quanzongliang@gmail.com>)
List 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 by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Re: make check For Extensions
Next
From: Pavel Stehule
Date:
Subject: Re: PL/pgSQL support to define multi variables once