Search Postgresql Archives

Re: Declare variable from other variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 5, 2020 at 2:22 PM Raul Kaubi <raulkaubi@xxxxxxxxx> 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; 

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux