Created
November 12, 2012 02:51
-
-
Save robertsosinski/4057243 to your computer and use it in GitHub Desktop.
Make a table readonly in Postgres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create trigger trades_readonly_trigger before insert or update or delete or truncate on trades for each statement execute procedure readonly_trigger_function(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function readonly_trigger_function() returns trigger as $$ | |
begin | |
raise exception 'The "%" table is read only!', TG_TABLE_NAME using hint = 'Look at tables that inherit from this table and write to them instead.'; | |
return null; | |
end; | |
$$ language 'plpgsql'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot!