I have two tables joined by a foreign key constraint:

CREATE TABLE test_master(
    id SERIAL PRIMARY KEY,
    foo TEXT
);

CREATE TABLE test_detail(
    id SERIAL PRIMARY KEY,
master BIGINT NOT NULL REFERENCES test_master(id) ON DELETE CASCADE ON UPDATE CASCADE,
    bar TEXT
);

Is there a way to block deletes on the "test_detail" table that will only allow rows to be deleted if it is the result of deleting the corresponding "test_master" record? In other words, I'd like to disallow direct DELETE commands like this:

DELETE FROM test_detail WHERE id = 1;

while allowing a command like

DELETE FROM test_master WHERE id = 1;

to subsequently delete via CASCADE all "test_detail" rows that reference test_master # 1.

I've tried using rules and revoking privileges, but both of these approaches fail when trying to delete from "test_master".

Thanks in advance,

Chris


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply via email to