Re: eval function - Mailing list pgsql-hackers

From Ziga Kranjec
Subject Re: eval function
Date
Msg-id 51930.193.77.243.249.1085341256.squirrel@webmail.ljudmila.org
Whole thread Raw
In response to Re: Latest requests from IRC  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
> Bruno Wolff III <bruno@wolff.to> writes:
>>   Christopher Kings-Lynne <chriskl@familyhealth.com.au> wrote:
>>> ... people want to be able to grant on all objects in a
>>> database, etc:

For things like this I use simple,
but super-powerful eval function:

CREATE OR REPLACE FUNCTION eval(text) RETURNS int4 VOLATILE LANGUAGE 'plpgsql' SECURITY INVOKER AS 'DECLARE body ALIAS
FOR$1; result INT; 
BEGIN
EXECUTE body;
GET DIAGNOSTICS result = ROW_COUNT;
RETURN result;
END;
';

Then you say something like:

SELECT eval('GRANT SELECT ON TABLE '||TABLE_NAME||' TO PUBLIC')
FROM INFORMATION_SCHEMA.TABLES
WHERE schema_name=current_schema()
AND type_type='BASE TABLE';

Also works great for other similar operations, such as
renaming, changing owners, etc... anything you can
generate with SQL, which is quite a lot, really.

Is this considered ok or extreme abuse?




pgsql-hackers by date:

Previous
From: Devrim GUNDUZ
Date:
Subject: Re: Fixing the Turkish problem
Next
From: Alvaro Herrera
Date:
Subject: Timezone fun (bugs and a request)