Re: CREATE VIEW (dynamically)

From: Christoph Haller <ch(at)rodos(dot)fzk(dot)de>
To: emmanuel(dot)engelhart(at)epita(dot)fr
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: CREATE VIEW (dynamically)
Date: 2002-11-12 13:57:48
Message-ID: 3DD108DC.B259364B@rodos.fzk.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2002-11-12 14:10:02 Re: parse bug
Previous Message Richard Huxton 2002-11-12 10:19:48 Re: