¿Desactivar BORRAR en la tabla en PostgreSQL?
Para un diseño sensible a la seguridad, me gustaría deshabilitarDELETEs
en ciertas mesas.
losDELETE
simplemente debe establecer undeleted
Bandera en una fila (que luego sería visible en una vista, que sería utilizada por la capa de aplicación).
Como entiendo unregla generaría consultas adicionales, por lo que una regla no podría suprimir la consulta original.
Como ejemplo, un ejemplo de juguete con un disparador (aún no probado):
-- data in this table should be 'undeletable'
CREATE table article (
id serial,
content text not null,
deleted boolean default false
)
-- some view that would only show articles, that are NOT deleted
...
-- toy trigger (not tested)
CREATE OR REPLACE FUNCTION suppress_article_delete()
RETURNS TRIGGER AS $sad$
BEGIN
IF (TG_OP = 'DELETE') THEN
UPDATE article SELECT id, content, TRUE;
-- NEW or NULL??
RETURN NEW;
END IF;
RETURN NULL;
END;
$sad$ LANGUAGE plpgsql;
¿Cuál sería una buena manera de suprimir unDELETE
?