PostgreSQL

1199 readers
1 users here now

The world's most advanced open source relational database

Project
Events
Podcasts
Related Fediverse communities

founded 2 years ago
MODERATORS
76
 
 

Example flow is on the image. Here I want to accomplish if playlist removed, make it delete image too.

I know I should've put FK on image table but Image is generic and its used more than once.

What are my options? Triggers and application-side comes to mind, but I'm not sure. Maybe there is a better way.

UPDATE: I guess I've found what I was looking for, rules:

CREATE RULE playlist_delete AS ON DELETE TO playlist WHERE (SELECT id FROM image WHERE image.id = OLD.image_id) IS NOT NULL DO INSTEAD NOTHING;

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
 

I understand that there are times with critical issues and outages when DBA are to work until all is fixed, which may take up to 20 hours.

But if things are stable and settled, out of a standard 8-9-hour work day, how many hours are actually needed to finish daily routine work?

95
96
97
98
99
 
 

pg-safeupdate is a PostgreSQL extension designed to prevent users from accidentally updating or deleting too many records in a single statement by requiring a "where" clause in all update and delete statements.

100
view more: ‹ prev next ›