Re: CREATE VIEW (dynamically) - Mailing list pgsql-sql

From Christoph Haller
Subject Re: CREATE VIEW (dynamically)
Date
Msg-id 3DD108DC.B259364B@rodos.fzk.de
Whole thread Raw
In response to CREATE VIEW (dynamically)  (Emmanuel Engelhart <"Emmanuel Engelhart"@postgresql.org>)
List pgsql-sql
> 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



pgsql-sql by date:

Previous
From: Cédric Dufour
Date:
Subject: Efficient ON DELETE trigger when referential integrity is involved ?
Next
From: Achilleus Mantzios
Date:
Subject: Re: parse bug