Re: help replacing expresion in plpgsql

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Juan Pablo L *EXTERN*" <jpablolorenzetti(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: help replacing expresion in plpgsql
Date: 2013-12-18 08:24:20
Message-ID: A737B7A37273E048B164557ADEF4A58B17C84A5C@ntex2010i.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Juan Pablo L wrote:
> Hi, i have a function that receives a parameter which represents days:
>
> FUNCTION aaa_recharge_account(expdays integer)
>
> i want to add those days to the CURRENT_DATE, but i do not know how to do it, i have tried several
> ways to replace that in an expresion like:
>
> newexpdate := CURRENT_TIMESTAMP + interval '$1 days' using expdays;
> (newexpdate is declared as timestamp)
>
> and many more but none work, can someone please help me to find out how can i replace that parameter
> into an expression that i can add to CURRENT_TIMESTAMP or any other way that i can accomplish what i
> need which is to add that parameter to the current timestamp. thanks!!!

There are many ways.
Two I can think of right away:

newexpdate := CURRENT_TIMESTAMP + CAST(expdays || ' days' AS interval);

newexpdate := CURRENT_TIMESTAMP + expdays * INTERVAL '1 days';

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2013-12-18 08:54:53 Re: Bus error in libxml2 in postgresql 9.2.x on FreeBSD
Previous Message Scott Marlowe 2013-12-18 05:53:16 Re: Question(s) about crosstab