Is it possible to only allow deletes from a table via referential integrity cascades?

Поиск
Список
Период
Сортировка
От Christopher Maier
Тема Is it possible to only allow deletes from a table via referential integrity cascades?
Дата
Msg-id 8F55A6E9-8A56-4261-B35A-5A7012D2C8CA@med.unc.edu
обсуждение исходный текст
Список pgsql-sql
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



В списке pgsql-sql по дате отправления:

Предыдущее
От: "Oliveiros Cristina"
Дата:
Сообщение: Re: Best way to "and" from a one-to-many joined table?
Следующее
От: "Allan Kamau"
Дата:
Сообщение: Re: Collapsing (select) row values into single text field.