Preventing DELETE and UPDATE without a WHERE clause? - Mailing list pgsql-hackers

From Chris Campbell
Subject Preventing DELETE and UPDATE without a WHERE clause?
Date
Msg-id 3F1249A4-61D7-413E-BAB1-C9BE8E0E9CC2@bignerdranch.com
Whole thread Raw
Responses Re: Preventing DELETE and UPDATE without a WHERE clause?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
I heard an interesting feature request today: preventing the  
execution of a DELETE or UPDATE query that does not have a WHERE clause.

The user was worried about a typo leading to:
   DELETE FROM very_important_table

and deleting all the data. Or doing something similar with an UPDATE:
   UPDATE very_important_table SET important_column = 'Smith'

and all the rows now have their important_column set to Smith.

I was thinking that this could be accomplished with a GUC to cause  
the server to report an error if DELETE and UPDATE queries don't  
contain WHERE clauses. "allow_mod_queries_without_qualifier" or  
something (which would obviously default to true).

If this setting was activated (the GUC changed to false), the above  
queries could still be executed, but it would take a conscious effort  
by the user to add a WHERE clause:
   DELETE FROM very_important_table WHERE true;   UPDATE very_important_table SET important_column = 'Smith' WHERE  
true;

Would such a patch ever be accepted?

Thanks!

- Chris



pgsql-hackers by date:

Previous
From: "Jaime Casanova"
Date:
Subject: Re: problems with the anoncvs?
Next
From: Tom Lane
Date:
Subject: Re: Preventing DELETE and UPDATE without a WHERE clause?