Re: Declare variable from other variable

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: Declare variable from other variable
Дата
Msg-id 29b33c88-102f-f0d3-3744-af53df41cb8b@gmx.net
обсуждение исходный текст
Ответ на Declare variable from other variable  (Raul Kaubi <raulkaubi@gmail.com>)
Список pgsql-general
Raul Kaubi schrieb am 05.02.2020 um 12:21:
> How can I declare another variable from another variable.
> Basically from oracle, I can just: 
>
>     var1 := 'asda'||var2;
>
> In postgres, I have the following example, I would like to use variable j to add number of months there.
>
>     " interval 'j month')::date; "
>
>
>     DO $$
>     DECLARE
>     v_var integer := 1;
>     v_from_date date;
>     BEGIN
>     for j in 0..v_var LOOP
>     v_from_date := (date_trunc('month',current_date) + interval 'j month')::date;
>     RAISE NOTICE '%', v_from_date;
>     END LOOP;
>     END;
>     $$ LANGUAGE plpgsql;

The easiest way is to use make_interval()

    v_from_date := (date_trunc('month',current_date) + make_interval(months => j))::date;


But it sounds as if generate_series() is what you are really looking for.



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

Предыдущее
От: Yasin Sari
Дата:
Сообщение: Re: Declare variable from other variable
Следующее
От: Raul Kaubi
Дата:
Сообщение: Re: Declare variable from other variable