You are counting the number of rows in the answer, and your query always returns a single line.
Your query says: return one row giving the number of students matching my criteria. If no one matches, you will get back one row with the value 0
. If you have 7 people matching, you will get back one row with the value 7
.
If you change your query to select * from ...
you will get the right answer from pg_num_rows()
.