Hay un error: ERROR: column "detienen" does not exist LINE 25: WHERE n.idnota =detienen ^