Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id E9CA59FA4CA for ; Thu, 11 Jan 2007 06:22:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 29817-07 for ; Thu, 11 Jan 2007 06:22:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id A37C79FA435 for ; Thu, 11 Jan 2007 06:22:36 -0400 (AST) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 5E39873E46; Thu, 11 Jan 2007 10:19:58 +0000 (GMT) Received: from [192.168.1.36] (unknown [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 33A792744FB; Thu, 11 Jan 2007 10:19:58 +0000 (GMT) Message-ID: <45A60F4D.8080305@archonet.com> Date: Thu, 11 Jan 2007 10:19:57 +0000 From: Richard Huxton User-Agent: IceDove 1.5.0.9 (X11/20061220) MIME-Version: 1.0 To: Marc Mamin Cc: pgsql-sql@postgresql.org Subject: Re: a way to generate functions dynamically ? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/30 X-Sequence-Number: 27182 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