That should not run twice. Perhaps you are putting an extra / in after the query that would make it run twice.
Also, I believe this is a simpler version of what you are doing:
select pyid from pca_work group by pyid having count(1) > 1;
The distinct is not necessary, they are already distinct because of the group by.