ERROR: syntax error at or near "AND" LINE 10: WHERE P.id= AND P.stamp IS NOT NULL ^