Re: Dynamic Query for System functions - now()

From: Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: Kumar <sgnerd(at)yahoo(dot)com(dot)sg>
Cc: Christoph Haller <ch(at)rodos(dot)fzk(dot)de>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Dynamic Query for System functions - now()
Date: 2003-11-10 12:18:24
Message-ID: Pine.LNX.4.44.0311101417470.1995-100000@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Kumar,
why dont you try

prepare fooplan2(int4) as select now() + ($1||' month')::interval;
execute fooplan2(12);

O kyrios Kumar egrapse stis Nov 10, 2003 :

> Dear Christoph Haller,
>
> The code that u sent is not working
> test=> EXECUTE 'select now()+ interval\'' ||to_char(3,'9')|| 'month\'';
> ERROR: parser: parse error at or near "'select now()+ interval\''" at
> character 9
> test=>
>
> Also I tried just to run the now() function with a dynamic query, I got the
> following error. Please correct me.
>
> test=> select now();
> now
> -------------------------------
> 2003-11-10 17:06:36.783779+00
> (1 row)
>
> test=> execute 'select now()';
> ERROR: parser: parse error at or near "'select now()'" at character 9
> test=>
>
>
> Regards
> kumar
>
> ----- Original Message -----
> From: "Christoph Haller" <ch(at)rodos(dot)fzk(dot)de>
> To: ""Kumar"" <sgnerd(at)yahoo(dot)com(dot)sg>
> Cc: <pgsql-sql(at)postgresql(dot)org>
> Sent: Monday, November 10, 2003 5:07 PM
> Subject: Re: [SQL] Dynamic Query for System functions - now()
>
>
> > >
> > > Dear Friends,
> > >
> > > I am using PostgreSQL 7.3.4 Server on RH Linux 7.2. I am trying to
> generate=
> > > a dynamic query to fetch the next month interval.
> > >
> > > select now()+ interval'1 month'; -- This is working fine.
> > >
> > > I wanna dynamically assign the interval number. i,e --> select now()+
> inter=
> > > val'n month';
> > >
> > > For this I wanted to write a dynamic query.
> > > EXECUTE 'select now()+ interval\'' || 3|| 'month\'';
> > > Error
> > > ERROR: parser: parse error at or near "'select now()+ interval\''"
> at =
> > > character 9
> > >
> > > Help help me with this. I wanted to use this query inside a PLpgSQL
> functio=
> > > n.
> > >
> > > Regards
> > > Kumar
> > >
> > You'd probably want to use the to_char() function like this
> > EXECUTE 'select now()+ interval\'' ||to_char(3,'9')|| 'month\'';
> >
> > The || operator is the string concatination operator.
> >
> > Regards, Christoph
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>

--
-Achilleus

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Holger Jakobs 2003-11-10 12:37:27 Re: transaction processing after error in statement
Previous Message Richard Huxton 2003-11-10 12:05:04 Re: FOR : Structure control pb