Skip site navigation (1) Skip section navigation (2)

Re: a way to generate functions dynamically ?

From: Richard Huxton <dev(at)archonet(dot)com>
To: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: a way to generate functions dynamically ?
Date: 2007-01-11 10:19:57
Message-ID: (view raw, whole thread or download thread mbox)
Lists: 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: 
>   RETURNS integer AS
> $BODY$
>     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

In response to

pgsql-sql by date

Next:From: Steve SabljakDate: 2007-01-11 12:22:21
Subject: Aggregating both tables in a join?
Previous:From: Marc MaminDate: 2007-01-11 08:29:56
Subject: a way to generate functions dynamically ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group