Friday, January 18, 2013

grant readonly access on selected table - Postgres 8.4

Task: To grant select only on tables inside database MYDB01 under schema warehouse_data to user READONLY

On postgres 8.x, Im not sure if its my problem only, but I cannot do one grant command on all tables, so searching the web and found that it can be done this way.


for i in `bin/psql MYDB01-A -t -c "SELECT table_name FROM information_schema.tables WHERE table_schema = 'warehouse_data';"`; do bin/psql ces_live_final -c "GRANT SELECT ON warehouse_data.$i TO READONLY;"; done

The above is one line only, and it solves my task.