X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 3B26FD1B54F for ; Mon, 10 Nov 2003 10:37:52 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 74781-08 for ; Mon, 10 Nov 2003 06:37:24 -0400 (AST) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id B5D2DD1B541 for ; Mon, 10 Nov 2003 06:37:20 -0400 (AST) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Mon Nov 10 11:37:17 2003 +0100 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id LAA26952; Mon, 10 Nov 2003 11:37:16 +0100 (MET) From: Christoph Haller Message-Id: <200311101037.LAA29518@rodos> Subject: Re: Dynamic Query for System functions - now() To: sgnerd@yahoo.com.sg ("Kumar") Date: Mon, 10 Nov 2003 11:37:15 MET Cc: pgsql-sql@postgresql.org In-Reply-To: <017701c3a75a$0e3e6050$7502a8c0@hdsc.com>; from "Kumar" at Nov 10, 103 8:19 am X-Mailer: Elm [revision: 212.4] X-Virus-Scanned: by amavisd-new at postgresql.org X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char 9C hex) in message header 'Received' Received: \234by rodos.fzk.de... ^ X-Archive-Number: 200311/80 X-Sequence-Number: 15895 > > 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