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 B4ECED1B531 for ; Wed, 15 Oct 2003 14:42:54 +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 64432-09 for ; Wed, 15 Oct 2003 11:42:27 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 227EAD1B53C for ; Wed, 15 Oct 2003 11:42:23 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id h9FEgMNu004256 for ; Wed, 15 Oct 2003 14:42:22 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h9FECqIc097616 for pgsql-sql@postgresql.org; Wed, 15 Oct 2003 14:12:52 GMT From: limr@yahoo.com (robert) X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Escaping the $1 parameter in stored procedures Date: 15 Oct 2003 07:12:44 -0700 Organization: http://groups.google.com Lines: 43 Message-ID: <75f517f5.0310150612.106c5d78@posting.google.com> References: <75f517f5.0310131218.3a2907e5@posting.google.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: groups-abuse@google.com To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/177 X-Sequence-Number: 15577 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