Re: [HACKERS] for row in select loop question - Mailing list pgsql-hackers

From jwieck@debis.com (Jan Wieck)
Subject Re: [HACKERS] for row in select loop question
Date
Msg-id m10IrOX-000EBQC@orion.SAPserv.Hamburg.dsh.de
Whole thread Raw
In response to for row in select loop question  (Michael Davis <michael.davis@prevuenet.com>)
List pgsql-hackers
>
> The following function does not work:
>
> CREATE FUNCTION InstallPermissions(varchar, varchar) RETURNS int2 AS '
>    DECLARE
>         options ALIAS FOR $1;
>         username ALIAS FOR $2;
> BEGIN
>    FOR row IN select * from pg_tables LOOP
>           REVOKE ALL ON row.tablename FROM username;
>           GRANT options on row.tablename TO username;
>    END LOOP;
>    return 0;
>  END; ' LANGUAGE 'plpgsql';
>
> "select InstallPermissions('test1', 'test2);"  returns an error at "select".
> Any suggestions on how to eliminate the error?

    First you forgot to declare 'row'. Could be type record.

    Second  REVOKE and GRANT are utility statements not supported
    for prepared SPI plans and  thus  PL/pgSQL  currently  cannot
    execute them.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#======================================== jwieck@debis.com (Jan Wieck) #

pgsql-hackers by date:

Previous
From: Oleg Broytmann
Date:
Subject: Re: [HACKERS] Not enough memory for complex join
Next
From: Oleg Broytmann
Date:
Subject: Bug on complex join