Re: Escaping the $1 parameter in stored procedures

From: limr(at)yahoo(dot)com (robert)
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Escaping the $1 parameter in stored procedures
Date: 2003-10-15 14:12:44
Message-ID: 75f517f5.0310150612.106c5d78@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Found a solution:

-- my_constraint(0) = turn off constraint
-- my_constraint(1) = turn ON constraint
CREATE OR REPLACE FUNCTION my_constraint(INTEGER)
RETURNS VARCHAR
AS '
DECLARE
cmd VARCHAR;
BEGIN
IF $1 = 0
THEN
RAISE NOTICE ''Turning OFF constraints'';
cmd := ''ALTER TABLE $tName DROP CONSTRAINT "$1"'';
EXECUTE cmd;
cmd := ''ALTER TABLE $tName DROP CONSTRAINT "$2"'';
EXECUTE cmd;
ELSE
RAISE NOTICE ''Turning ON constraints'';
ALTER TABLE $tName
ADD FOREIGN KEY(key1) REFERENCES table1;
ALTER TABLE $tName
ADD FOREIGN KEY(key2) REFERENCES table2;
END IF;
RETURN ''OK'';
END;'
LANGUAGE plpgsql;"

limr(at)yahoo(dot)com (robert) wrote in message news:<75f517f5(dot)0310131218(dot)3a2907e5(at)posting(dot)google(dot)com>...
> I'm running Postgres 7.3.2 in Redhat 9.0.
>
> I'm trying to execute a function below defined as a stored procedure
>
> ALTER TABLE tms_schedule DROP CONSTRAINT "$1";
>
> However, postgres thinks the "$1" is a parameter value. How do I tell
> postgres to treat it as a literal $1?
>
> TIA,
> Robert

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message greg 2003-10-15 14:48:37 Re: How can I produce the following desired result?
Previous Message Richard Huxton 2003-10-15 13:17:46 Re: about postgre SQL download