Coming from Oracle world, I also was missing the ability to execute anonymous 
blocks.
So I wrote this function:

CREATE OR REPLACE FUNCTION exec_plpgsql_block(exec_string text)
RETURNS BOOLEAN
AS $THIS$
DECLARE lRet BOOLEAN;
BEGIN
EXECUTE 'CREATE OR REPLACE FUNCTION any_block()
RETURNS VOID
AS $$ ' || exec_string || ' $$LANGUAGE PLPGSQL;' ;
PERFORM any_block();
RETURN TRUE;
END;
$THIS$LANGUAGE PLPGSQL;

to which I pass my "anonymous" block as a parameter.
As you can see, this function creates/replaces "on the fly" function 
"any_block()" and executes it.
Pretty simple solution.

Igor Neyman


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tom Lane
Sent: Thursday, May 24, 2007 11:12 AM
To: Abraham, Danny
Cc: pgsql-admin@postgresql.org; Devrim GÜNDÜZ
Subject: Re: [ADMIN] anonymous block in Postgres - Hello World 

"Abraham, Danny" <[EMAIL PROTECTED]> writes:
> This code is my first "like Oracle anonymous blocl". It does not go = 
> through.

There are no anonymous blocks in Postgres --- you must create a function.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

Reply via email to