Re: PL/pgSQL support to define multi variables once

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Quan Zongliang <quanzongliang(at)gmail(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PL/pgSQL support to define multi variables once
Date: 2014-06-13 15:39:44
Message-ID: 20140613153943.GM18688@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 $$
declare
a, b, c text;
begin
a := 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2014-06-13 15:44:54 Re: PL/pgSQL support to define multi variables once
Previous Message David E. Wheeler 2014-06-13 15:33:31 Re: make check For Extensions