Re: anonymous block in Postgres - Hello World - Mailing list pgsql-admin

From Igor Neyman
Subject Re: anonymous block in Postgres - Hello World
Date
Msg-id F4C27E77F7A33E4CA98C19A9DC6722A201F01BF9@EXCHANGE.corp.perceptron.com
Whole thread Raw
In response to Re: anonymous block in Postgres - Hello World  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: anonymous block in Postgres - Hello World  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-admin
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: pgsql-admin-owner@postgresql.org [mailto:pgsql-admin-owner@postgresql.org] 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" <danny_abraham@bmc.com> 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


pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: anonymous block in Postgres - Hello World
Next
From: Tom Lane
Date:
Subject: Re: Can't drop tables ERROR: cache lookup failed for relation 411727