Skip site navigation (1) Skip section navigation (2)

Re: Anonymous code blocks

From: Petr Jelinek <pjmodos(at)pjmodos(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Dimitri Fontaine <dfontaine(at)hi-media(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Subject: Re: Anonymous code blocks
Date: 2009-09-23 04:26:37
Message-ID: 4AB9A37D.4020104@pjmodos.net (view raw or flat)
Thread:
Lists: pgsql-hackers
Tom Lane napsal(a):
> Petr Jelinek <pjmodos(at)pjmodos(dot)net> writes:
>   
>>  [ anonymous code blocks patch ]
>>     
>
> I committed this after some editorialization.  Aside from adding missing
> CREATE LANGUAGE and pg_dump support, I didn't like the API for inline
> handler functions.  Passing just a C string doesn't allow for any future
> expansibility (eg adding parameters), and it represents a security hole
> because anyone could call the function, thereby bypassing the privilege
> checks.  I changed things so that the inline handlers are declared as
> taking type INTERNAL, which will prevent them from being called manually
> from SQL.  Also, I made the actual argument be a new Node struct type.
> (I first thought of passing the DO statement's parse node as-is, but
> that would require every handler to re-implement the deconstruction of
> the DefElem list.  So a separate struct type seemed like a better idea.)
> With this, we can add parameters or what have you without any changes
> in the catalog-level representation of the languages or inline handlers.
> I did some renaming too --- we generally expect that parsenodes
> associated with statement types are named after the statement, for
> instance.
>   

Good work as always, thanks.

> The do.sgml file was missing from both your submissions, so I cooked
> up a very quick-and-dirty reference page.  It could stand to be fleshed
> out a bit, probably.  If there's useful material in your original,
> please submit a followon patch to add it.
>   

Aside from worse wording in my version the only difference is the example.
I used (and I am killing GRANT ON ALL patch now):
  <para>
   Grant all privileges on all VIEWs in schema <literal>public</> to 
role <literal>webuser</>.
<programlisting>
DO $$DECLARE r record;
BEGIN
    FOR r IN SELECT table_schema, table_name FROM information_schema.tables
             WHERE table_type = 'VIEW' AND table_schema = 'public'
    LOOP
        EXECUTE 'GRANT ALL ON ' || quote_literal(r.table_schema) || '.' 
|| quote_literal(r.table_name) || ' TO webuser';
    END LOOP;
END$$;
</programlisting>
  </para>
 

-- 
Regards
Petr Jelinek (PJMODOS)

In response to

Responses

pgsql-hackers by date

Next:From: Mark KirkwoodDate: 2009-09-23 06:18:51
Subject: Re: Lock Wait Statistics (next commitfest)
Previous:From: Tom LaneDate: 2009-09-23 03:21:57
Subject: Re: LATERAL

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group