pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedEscaping the $1 parameter in stored procedures
2+ messages / 1 participants
[nested] [flat]
* Escaping the $1 parameter in stored procedures
@ 2003-10-13 20:18 robert <limr@yahoo.com>
0 siblings, 1 reply; 2+ messages in thread
From: limr@yahoo.com @ 2003-10-13 20:18 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Escaping the $1 parameter in stored procedures
@ 2003-10-15 14:12 robert <limr@yahoo.com>
parent: robert <limr@yahoo.com>
0 siblings, 0 replies; 2+ messages in thread
From: limr@yahoo.com @ 2003-10-15 14:12 UTC (permalink / raw)
To: 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@yahoo.com (robert) wrote in message news:<75f517f5.0310131218.3a2907e5@posting.google.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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-10-15 14:12 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-10-13 20:18 Escaping the $1 parameter in stored procedures robert <limr@yahoo.com>
2003-10-15 14:12 ` robert <limr@yahoo.com>
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