Las tablas que referencian a la tablamdp_datos_censales son las siguientes:
mdp_datos_actividades
mdp_datos_economicos
mdp_datos_personales
mdp_eleccion_institucion
mdp_eleccion_propuesta
mdp_personas_allegados
Lo podes ver con la siguiente consulta:
select conname as "Foreign Key",
t1.relname as "Tabla que referencia",
a1.attname as "Columna que referencia",
t2.relname as "Tabla referenciada",
a2.attname as "Columna referenciada"
from pg_constraint as c,
pg_class as t1,
pg_class as t2,
pg_attribute as a1,
pg_attribute as a2
where
t2.relname = 'mdp_datos_censales'
and c.conrelid = t1.relfilenode
and t2.relfilenode = c.confrelid
and a1.attrelid = t1.relfilenode
and a2.attrelid = t2.relfilenode
--and a1.attnum = any (c.conkey)
--and a2.attnum = any (c.confkey)
and (
( c.conkey[1] = a1.attnum and c.confkey[1] = a2.attnum ) OR
( c.conkey[2] = a1.attnum and c.confkey[2] = a2.attnum ) OR
( c.conkey[3] = a1.attnum and c.confkey[3] = a2.attnum ) OR
( c.conkey[4] = a1.attnum and c.confkey[4] = a2.attnum ) OR
( c.conkey[5] = a1.attnum and c.confkey[5] = a2.attnum ) OR
( c.conkey[6] = a1.attnum and c.confkey[6] = a2.attnum ) OR
( c.conkey[7] = a1.attnum and c.confkey[7] = a2.attnum ) OR
( c.conkey[8] = a1.attnum and c.confkey[8] = a2.attnum ) OR
( c.conkey[9] = a1.attnum and c.confkey[9] = a2.attnum ) OR
( c.conkey[10] = a1.attnum and c.confkey[10] = a2.attnum )
)
order by conname
;
En ese script 02_mdp_datos_censales, donde estan los DELETES al comienzo, faltaria borrar los datos de esas dos tablas. Deberías agregar estos DELETES:
DELETE FROM mdp_eleccion_propuesta WHERE dato_censal IN (SELECT dato_censal FROM _temp_dc);
DELETE FROM mdp_eleccion_institucion WHERE dato_censal IN (SELECT dato_censal FROM _temp_dc);
DELETE FROM his_eleccion_propuesta WHERE dato_censal IN (SELECT dato_censal FROM _temp_dc);
DELETE FROM his_eleccion_institucion WHERE dato_censal IN (SELECT dato_censal FROM _temp_dc);