Re: a way to generate functions dynamically ? - Mailing list pgsql-sql

From Richard Huxton
Subject Re: a way to generate functions dynamically ?
Date
Msg-id 45A60F4D.8080305@archonet.com
Whole thread Raw
In response to a way to generate functions dynamically ?  ("Marc Mamin" <M.Mamin@intershop.de>)
List pgsql-sql
Marc Mamin wrote:
> Hello, 
>  
> I need to generate some procedures that depend  data models stored in my
> DBs. 
> As I have different models in different databases, the stored procedures
> will differ.
>  
> My idea is to generate the required stored procedures dynamically once a
> model is defined.
> I will probably do this within the application. But is there a way to
> achieve this with plpgsql ?
>  
> here a naive try to illustrate  my idea: 
>  
> CREATE OR REPLACE FUNCTION test(p1 int)
>   RETURNS integer AS
> $BODY$
>  
> EXECUTE'
>     CREATE OR REPLACE FUNCTION generated(p2 int)
>     RETURNS integer AS
>     $BODY$
>      BEGIN

>  ERROR: syntax error at or near "BEGIN"
> SQL state: 42601

The only mistake is in the $$ quoting. It thinks the second $BODY$ is 
closing the first. You'll need to generate a different quote-identifier 
(e.g. $CUSTOM$).

--   Richard Huxton  Archonet Ltd


pgsql-sql by date:

Previous
From: "Marc Mamin"
Date:
Subject: a way to generate functions dynamically ?
Next
From: "Steve Sabljak"
Date:
Subject: Aggregating both tables in a join?