Declare variable from other variable

From: Raul Kaubi <raulkaubi(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Declare variable from other variable
Date: 2020-02-05 11:21:44
Message-ID: CAO_+3-BRGqQXs4SNi8eaEyBNbzCODFVYJvDVJZBEDSQtA+68qg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

PostgreSQL 12.1

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;

> ERROR: invalid input syntax for type interval: "j month"
> LINE 1: ...LECT (date_trunc('month',current_date) + interval 'j month')...

Raul

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raul Kaubi 2020-02-05 11:22:20 Re: Get rid of brackets around variable
Previous Message Nick Renders 2020-02-05 11:14:21 Unable to startup postgres: Could not read from file "pg_clog/00EC"