Skip to content

Instantly share code, notes, and snippets.

@robertsosinski
Created November 12, 2012 02:51
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertsosinski/4057243 to your computer and use it in GitHub Desktop.
Save robertsosinski/4057243 to your computer and use it in GitHub Desktop.
Make a table readonly in Postgres
create trigger trades_readonly_trigger before insert or update or delete or truncate on trades for each statement execute procedure readonly_trigger_function();
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';
Copy link

ghost commented Sep 12, 2015

Thanks a lot!

@kevinwu
Copy link

kevinwu commented Dec 1, 2015

thanks from me as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment