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