Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 497EC47632D for ; Tue, 12 Nov 2002 08:57:50 -0500 (EST) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by postgresql.org (Postfix) with SMTP id 336C54762FA for ; Tue, 12 Nov 2002 08:57:49 -0500 (EST) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Tue Nov 12 14:57:49 2002 +0100 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id OAA11505; Tue, 12 Nov 2002 14:57:48 +0100 (MET) Message-ID: <3DD108DC.B259364B@rodos.fzk.de> Date: Tue, 12 Nov 2002 14:57:48 +0100 From: Christoph Haller X-Mailer: Mozilla 4.06 [en] (X11; I; HP-UX B.10.20 9000/780) MIME-Version: 1.0 To: emmanuel.engelhart@epita.fr Cc: pgsql-sql@postgresql.org Subject: Re: CREATE VIEW (dynamically) Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/181 X-Sequence-Number: 10323 > CREATE FUNCTION "requests_insert_after" () RETURNS opaque AS ' > DECLARE > view_name text; > BEGIN > view_name := ''request_'' || NEW.id; > CREATE VIEW view_name AS select * from groups; > return NEW; > END' LANGUAGE 'plpgsql'; > > CREATE TRIGGER "requests_insert_after" AFTER INSERT ON "requests" FOR EACH ROW > EXECUTE PROCEDURE "requests_insert_after" ();>> > > This code after an insertion on table "requests" give me this message : > << > PostgreSQL said: ERROR: parser: parse error at or near "$1" > >> > > Why ? > You should check the documentation of plpgsql for the section Executing dynamic queries (which also means commands like update, etc.) e.g. to drop a view within plpgsql you have to code EXECUTE ''DROP VIEW '' || quote_ident( view_name) ; Regards, Christoph