Re: anonymous block in Postgres - Hello World

From: "Igor Neyman" <ineyman(at)perceptron(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Abraham, Danny" <danny_abraham(at)bmc(dot)com>
Cc: <pgsql-admin(at)postgresql(dot)org>, Devrim GÜNDÜZ <devrim(at)gunduz(dot)org>
Subject: Re: anonymous block in Postgres - Hello World
Date: 2007-05-24 15:31:33
Message-ID: F4C27E77F7A33E4CA98C19A9DC6722A201F01BF9@EXCHANGE.corp.perceptron.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)postgresql(dot)org [mailto:pgsql-admin-owner(at)postgresql(dot)org] On Behalf Of Tom Lane
Sent: Thursday, May 24, 2007 11:12 AM
To: Abraham, Danny
Cc: pgsql-admin(at)postgresql(dot)org; Devrim GÜNDÜZ
Subject: Re: [ADMIN] anonymous block in Postgres - Hello World

"Abraham, Danny" <danny_abraham(at)bmc(dot)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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2007-05-24 15:32:49 Re: Can't drop tables ERROR: cache lookup failed for relation 411727
Previous Message Tom Lane 2007-05-24 15:12:17 Re: anonymous block in Postgres - Hello World