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


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to