What's the proper way to block a table from further insert ? Postgresql

11 Views Asked by At

My table has three rows and i don't want to add any more rows.

However i want to be able to select & update on the table.

What is the best way to block further inserts ?

1

There are 1 best solutions below

0
On BEST ANSWER

Assuming you have a primary key named id with the current values 1,2 and 3 you could do something like this:

alter table the_table 
   add constraint limit_values check (id in (1,2,3));

Now if you try to insert a new row, you either get a primary key violation (because 1,2 and 3 already exist) or you get a check constraint violation when you try to insert a different ID value that does not yet exist.