postgresql function select count into variable