Executing Anonymous Blocks

Started by imadalmost 21 years ago4 messages
#1imad
immaad@gmail.com

hi,

I want to know is there any way to execute an anonymous PL/pgSQL block
in PostgreSQL.

Thanx

--

Regards
Imad

#2Alvaro Herrera
alvherre@dcc.uchile.cl
In reply to: imad (#1)
Re: Executing Anonymous Blocks

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.

--
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
Al principio era UNIX, y UNIX habl� y dijo: "Hello world\n".
No dijo "Hello New Jersey\n", ni "Hello USA\n".

#3Neil Conway
neilc@samurai.com
In reply to: Alvaro Herrera (#2)
Re: Executing Anonymous Blocks

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.

-Neil

#4Andrew Dunstan
andrew@dunslane.net
In reply to: Neil Conway (#3)
Re: Executing Anonymous Blocks

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