pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Marc Mamin <M.Mamin@intershop.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: a way to generate functions dynamically ?
Date: Thu, 11 Jan 2007 10:19:57 +0000
Message-ID: <45A60F4D.8080305@archonet.com> (raw)
In-Reply-To: <CA896D7906BF224F8A6D74A1B7E54AB30175095D@JENMAIL01.ad.intershop.net>
References: <CA896D7906BF224F8A6D74A1B7E54AB30175095D@JENMAIL01.ad.intershop.net>

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



view thread (2+ messages)

Message-ID: <45A60F4D.8080305@archonet.com>
Permalink:  ../45A60F4D.8080305@archonet.com/
Also on:    postgresql.org/message-id/45A60F4D.8080305@archonet.com

 · 

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: dev@archonet.com, M.Mamin@intershop.de
  Subject: Re: a way to generate functions dynamically ?
  In-Reply-To: <45A60F4D.8080305@archonet.com>

* 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