0

Attempting to adapt this solution, but for revoking privileges in this way:

DO
$$
DECLARE
    t record;
BEGIN
    FOR t IN
        SELECT table_schema, table_name
        FROM information_schema.tables
        WHERE table_schema = 'my_schema'
        AND table_name LIKE 'test\_%'
        LOOP
            EXECUTE format('REVOKE DELETE, INSERT, UPDATE ON TABLE %I.%I FROM test;', table_schema, table_name);
        END LOOP;
END;
$$ LANGUAGE plpgsql;

However, I'm getting "column table_schema does not exist". Am I approaching this the right way?

Using postgresql 9.6 (french locale).

2 Answers 2

3

You need to reference the record of the cursor loop:

EXECUTE format('REVOKE DELETE, INSERT, UPDATE ON TABLE %I.%I FROM test;', 
               t.table_schema, t.table_name);
               ^-- here        ^-- here
1

Or use psql and run

SELECT format(
          'REVOKE DELETE, INSERT, UPDATE ON TABLE %I.%I FROM test;',
          table_schema,
          table_name
       )
FROM information_schema.tables
WHERE table_schema = 'my_schema'
AND table_name LIKE 'test\_%' \gexec

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.