pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedCREATE VIEW (dynamically)
2+ messages / 2 participants
[nested] [flat]
* CREATE VIEW (dynamically)
@ 2002-11-09 14:52 Emmanuel Engelhart <Emmanuel Engelhart@postgresql.org>
0 siblings, 0 replies; 2+ messages in thread
From: Emmanuel Engelhart @ 2002-11-09 14:52 UTC (permalink / raw)
To: pgsql-sql; +Cc: emmanuel.engelhart@epita.fr
code
<<
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 ?
Thx for any help.
Emmanuel Engelhart
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: CREATE VIEW (dynamically)
@ 2002-11-12 13:57 Christoph Haller <ch@rodos.fzk.de>
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Haller @ 2002-11-12 13:57 UTC (permalink / raw)
To: emmanuel.engelhart@epita.fr; +Cc: 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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-11-12 13:57 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-11-09 14:52 CREATE VIEW (dynamically) Emmanuel Engelhart <Emmanuel Engelhart@postgresql.org>
2002-11-12 13:57 Re: CREATE VIEW (dynamically) Christoph Haller <ch@rodos.fzk.de>
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