CREATE TEMPORARY TABLE rd_deleted AS
(
    SELECT rd_id deleted_id
    FROM rd
    EXCEPT
    (
        SELECT rd_id FROM rd_rd_el
        INTERSECT
        SELECT rd_id FROM rd_nm
    )
);

CREATE TEMPORARY TABLE addr_deleted AS
(
    SELECT addr_id deleted_id FROM addr
    JOIN rd_deleted ON (rd_id = deleted_id)
);

DELETE FROM rd USING rd_deleted WHERE rd_id = deleted_id;
DELETE FROM rd_ad USING rd_deleted WHERE rd_id = deleted_id;
DELETE FROM rd_ft USING rd_deleted WHERE rd_id = deleted_id;
DELETE FROM rd_rd_el USING rd_deleted WHERE rd_id = deleted_id;
DELETE FROM rd_nm USING rd_deleted WHERE rd_id = deleted_id;

DELETE FROM addr USING addr_deleted WHERE addr_id = deleted_id;
DELETE FROM addr_nm USING addr_deleted WHERE addr_id = deleted_id;
DELETE FROM ft_addr USING addr_deleted WHERE addr_id = deleted_id;
DELETE FROM node USING addr_deleted WHERE node_id = deleted_id; /*node_id == addr_id for all address points*/
