Re: Declare variable from other variable

From: Yasin Sari <yasinsari81(at)googlemail(dot)com>
To: Raul Kaubi <raulkaubi(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Declare variable from other variable
Date: 2020-02-05 12:28:25
Message-ID: CADhAfgMa-6cD3bXXJS_6HGp+4JZ_mBdSYNNynsqEr0wYgGpnug@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Feb 5, 2020 at 2:22 PM Raul Kaubi <raulkaubi(at)gmail(dot)com> wrote:

>
> 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;
>
>
>> ERROR: invalid input syntax for type interval: "j month"
>> LINE 1: ...LECT (date_trunc('month',current_date) + interval 'j
>> month')...
>
>
>
>
If you replace red line with this one it will work:

v_from_date := (date_trunc('month',current_date) + interval '1
month'*j)::date;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2020-02-05 12:29:05 Re: Declare variable from other variable
Previous Message Alvaro Herrera 2020-02-05 11:51:16 Re: Unable to startup postgres: Could not read from file "pg_clog/00EC"