Soft delete in postgresql using rules
If you want to mark a row of your database as being "deleted" instead of actually removing it, you can create a rule that does that:
CREATE OR REPLACE RULE delete_venue AS
ON DELETE TO venues DO INSTEAD
UPDATE venues
SET active = 'f'
WHERE venues.venue_id = old.venue_id;
This way the active
column will be set to false instead of removing the row from the database.
Another way would use a field named deleted_at
and set it to the current date, so you would know when it was deleted.
Written by Felipe Elias Philipp
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Postgres
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#