pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christoph Haller <ch@rodos.fzk.de>
To: emmanuel.engelhart@epita.fr
Cc: pgsql-sql@postgresql.org
Subject: Re: CREATE VIEW (dynamically)
Date: Tue, 12 Nov 2002 14:57:48 +0100
Message-ID: <3DD108DC.B259364B@rodos.fzk.de> (raw)

> 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




view thread (2+ messages)

Message-ID: <3DD108DC.B259364B@rodos.fzk.de>
Permalink:  ../3DD108DC.B259364B@rodos.fzk.de/
Also on:    postgresql.org/message-id/3DD108DC.B259364B@rodos.fzk.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ch@rodos.fzk.de, emmanuel.engelhart@epita.fr
  Subject: Re: CREATE VIEW (dynamically)
  In-Reply-To: <3DD108DC.B259364B@rodos.fzk.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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