Newbie question about escaping in a function

From: "Naeem Bari" <naeem(dot)bari(at)agilissystems(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Newbie question about escaping in a function
Date: 2004-10-26 16:57:00
Message-ID: 53F35087CC531844AD19CCAE6FA66929368C@util.agilissystems.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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! :-)

Thanks,
naeem

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Devrim GUNDUZ 2004-10-26 17:18:20 [SECURITY] New set of PostgreSQL RPMS are available for download
Previous Message Joshua D. Drake 2004-10-26 16:48:50 Re: primary key and existing unique fields