Re: Re: Support plpgsql multi-range in conditional control - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: Re: Support plpgsql multi-range in conditional control
Date
Msg-id CAFj8pRBKxS0LQePGT5n-5RK3A0eMAqFMimHMgDdSU4HdP8Ufqw@mail.gmail.com
Whole thread Raw
In response to Re: Re: Support plpgsql multi-range in conditional control  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers


čt 19. 1. 2023 v 16:54 odesílatel Pavel Stehule <pavel.stehule@gmail.com> napsal:


čt 19. 1. 2023 v 15:20 odesílatel 2903807914@qq.com <2903807914@qq.com> napsal:
Hello, thank you very much for your reply. But I think you may have misunderstood what we have done. 

What we do this time is that we can use multiple range ranges (condition_iterator) after in. Previously, we can only use such an interval [lower, upper] after in, but in some scenarios, we may need a list: condition_ iterator[,condition_iterator ...]

condition_iterator:
[ REVERSE ] expression .. expression [ BY expression ] 

then you can use second outer for over an array or just while cycle

I wrote simple example:

create type range_expr as (r int4range, s int);

do
$$
declare re range_expr;
begin
  foreach re in array ARRAY[('[10, 20]', 1), ('[100, 200]', 10)]
  loop
    for i in lower(re.r) .. upper(re.r) by re.s
    loop
      raise notice '%', i;
    end loop;
  end loop;
end;
$$;


But just I don't know what is wrong on

begin
  for i in 10..20
  loop
    raise notice '%', i;
  end loop;

  for i in 100 .. 200 by 10
  loop
    raise notice '%', i;
  end loop;
end;

and if there are some longer bodies you should use function or procedure. Any different cycle is separated. PLpgSQL (like PL/SQL or ADA) are verbose languages. There is no goal to have short, heavy code.

Regards

Pavel



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Rethinking the implementation of ts_headline()
Next
From: Justin Pryzby
Date:
Subject: Re: Remove source code display from \df+?