Why have you included this command and put the result in the variable before and at the end of the while loop, instead of just putting it in the while condition, like this?

```while [ $(su - postgres -c "psql -t -d rudder -c \"select count(*) from  (select distinct(nodeid) from ruddersysevents_old) as T;\"") -gt 0 ]```