Re: Newbie question about escaping in a function

From: Thomas F(dot)O'Connell <tfo(at)sitening(dot)com>
To: "Naeem Bari" <naeem(dot)bari(at)agilissystems(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Newbie question about escaping in a function
Date: 2004-10-27 15:56:39
Message-ID: C9D3CE59-2830-11D9-B369-000D93AE0944@sitening.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Try using EXECUTE.

http://www.postgresql.org/docs/7.4/static/plpgsql-
statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

-tfo

--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC
http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-260-0005

On Oct 26, 2004, at 11:57 AM, Naeem Bari wrote:

> I have a simple function defined thusly:
>
>  
>
> CREATE OR REPLACE FUNCTION datemath(timestamp with time zone, int4,
> varchar)
>
>   RETURNS timestamp AS
>
> '
>
> DECLARE
>
>   tdat timestamp;
>
>   rdat timestamp;
>
> BEGIN
>
>   IF ($1 IS NULL) THEN
>
>     TDAT := NOW();
>
>   ELSE
>
>     TDAT := $1;
>
>   END IF;
>
>  
>
>   select tdat + interval ''$2 $3'' into rdat;
>
>   return rdat;
>
> END;
>
> '
>
>   LANGUAGE 'plpgsql' VOLATILE;
>
>  
>
> The problem is the interval part. How do I tell the bugger to use the
> second and third params as input to interval? I have tried different
> ways of escaping, from \’$2 $3\’ to ‘’$2 $3’’ and everything else in
> between, it just doesn’t like it.
>
>  
>
> Help! J
>
>  
>
> Thanks,
>
> naeem

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pierre-Frédéric Caillaud 2004-10-27 15:59:46 Re: Array values and foreign keys
Previous Message nd02tsk 2004-10-27 15:56:16 Reasoning behind process instead of thread based arch?