create table delincuente(
	id bigserial PRIMARY KEY,
	nombre character varying(36) UNIQUE,
	sexo character varying(1) CHECK (lower(sexo)= 'm' or lower(sexo) = 'h')
);

insert into delincuente values(default,'El Indio Juan','h');

CREATE TABLE atributos(
	id bigserial PRIMARY KEY,
	nombre character varying(36) UNIQUE
);

insert into atributos values(default,'color de la piel');
insert into atributos values(default,'color de los ojos');
insert into atributos values(default,'tipo de boca');
insert into atributos values(default,'tipo de cejas');
insert into atributos values(default,'cantidad de dedos');
insert into atributos values(default,'cabezas');

CREATE TABLE valores(
	id bigserial PRIMARY KEY,
	id_atributo bigint REFERENCES atributos(id),
	valor character varying(36),
	UNIQUE (valor,id_atributo)
);

insert into valores values(default,1,'blanco');
insert into valores values(default,1,'negro');
insert into valores values(default,1,'amarillo');
insert into valores values(default,2,'cafe');
insert into valores values(default,2,'azul');
insert into valores values(default,2,'verde');
insert into valores values(default,3,'chica');
insert into valores values(default,3,'grande');
insert into valores values(default,4,'chica');
insert into valores values(default,4,'grande');
insert into valores values(default,5,'21');
insert into valores values(default,6,'2');

create table caracteristicas(
	id_delincuente bigint REFERENCES delincuente(id),
	id_atributo bigint REFERENCES atributos(id),
	id_valor bigint REFERENCES valores(id),
	UNIQUE (id_delincuente,id_atributo)
);

insert into caracteristicas values(1,1,1);
insert into caracteristicas values(1,2,4);
insert into caracteristicas values(1,3,7);
insert into caracteristicas values(1,4,9);
insert into caracteristicas values(1,5,11);
insert into caracteristicas values(1,6,12);


select d.nombre, a.nombre, v.valor from delincuente d, caracteristicas c, atributos a, valores v where d.id = c.id_delincuente and a.id = c.id_atributo and v.id = c.id_valor;
