pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: George Weaver <georgew1@mts.net>
To: Kumar <sgnerd@yahoo.com.sg>
To: Christoph Haller <ch@rodos.fzk.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: Dynamic Query for System functions - now()
Date: Mon, 10 Nov 2003 07:55:49 -0600
Message-ID: <006401c3a792$7182b0c0$6400a8c0@cleartag> (raw)
References: <200311101037.LAA29518@rodos>
	<03b801c3a781$c9d9cda0$7502a8c0@hdsc.com>

Kumar,

What about this:

EXECUTE 'select now()+ interval \' || to_char(3,\'9\') || \'month\' ';

George

----- Original Message ----- 
From: "Kumar" <sgnerd@yahoo.com.sg>
To: "Christoph Haller" <ch@rodos.fzk.de>
Cc: <pgsql-sql@postgresql.org>
Sent: Monday, November 10, 2003 5:57 AM
Subject: Re: [SQL] Dynamic Query for System functions - now()


> 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@rodos.fzk.de>
> To: ""Kumar"" <sgnerd@yahoo.com.sg>
> Cc: <pgsql-sql@postgresql.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
>




view thread (8+ messages)  latest in thread

Message-ID: <006401c3a792$7182b0c0$6400a8c0@cleartag>
Permalink:  ../006401c3a792$7182b0c0$6400a8c0@cleartag/
Also on:    postgresql.org/message-id/006401c3a792$7182b0c0$6400a8c0@cleartag

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: georgew1@mts.net, sgnerd@yahoo.com.sg, ch@rodos.fzk.de
  Subject: Re: Dynamic Query for System functions - now()
  In-Reply-To: <006401c3a792$7182b0c0$6400a8c0@cleartag>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox