X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 30DA752A71 for ; Tue, 29 Mar 2005 12:46:17 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 12548-02 for ; Tue, 29 Mar 2005 11:46:12 +0000 (GMT) Received: from trolak.mydnsbox2.com (ns1.mydnsbox2.com [207.44.142.118]) by svr1.postgresql.org (Postfix) with ESMTP id DF29E52951 for ; Tue, 29 Mar 2005 12:46:10 +0100 (BST) Received: from dunslane.net (localhost.localdomain [127.0.0.1]) (authenticated (0 bits)) by trolak.mydnsbox2.com (8.11.6/8.11.6) with ESMTP id j2TBtsK07129; Tue, 29 Mar 2005 05:55:55 -0600 Received: from 24.211.165.134 (SquirrelMail authenticated user andrew@dunslane.net) by www.dunslane.net with HTTP; Tue, 29 Mar 2005 05:55:55 -0600 (CST) Message-ID: <1089.24.211.165.134.1112097355.squirrel@www.dunslane.net> Date: Tue, 29 Mar 2005 05:55:55 -0600 (CST) Subject: Re: Executing Anonymous Blocks From: "Andrew Dunstan" To: In-Reply-To: <42490AF0.6040704@samurai.com> References: <42490AF0.6040704@samurai.com> X-Priority: 3 Importance: Normal X-MSMail-Priority: Normal Cc: , , X-Mailer: SquirrelMail (version 1.2.5) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200503/1011 X-Sequence-Number: 65813 Neil Conway said: > Alvaro Herrera wrote: >> On Mon, Mar 28, 2005 at 12:27:18PM +0500, imad wrote: >>>I want to know is there any way to execute an anonymous PL/pgSQL block >>>in PostgreSQL. >> >> No, there isn't. > > It might be possible to implement at least some of this functionality > entirely in the client. So: > > BLOCK; > /* your pl/pgsql code here */ > END BLOCK; > > Could be transformed by the client app to: > > CREATE FUNCTION anon_xxx() AS '/* your pl/pgsql code here' > RETURNS void LANGUAGE 'plpgsql'; > SELECT anon_xxx(); > DROP FUNCTION anon_xxx(); > > This would be pretty limited -- you couldn't get a return value from > the anonymous block, for example -- but I can see it being useful in > some situations. > I don't see that performing the same transformation at the SQL level would be any harder. Then if we ever got SQL host variables we might have a good way of using them ;-). Of course, another question is whether we should make plpgsql special, or allow anonymous blocks in any supported language. cheers andrew