Tzaddik can be used in two ways.
One is the loose use of the word which the Talmud often uses to refer to anyone who has more good deeds than bad ones.Such a person on judgemet day will be stamped "Righteous" as opposed to "Evil". But that's just like in a court case when somone is proclaimed "innocent". It doesn't mean he's perfect, it just means he's won this particular case.
I'm thinking of a story in connection with this. I'm probably going to mess it up, but this is how I remember this.
One Jew found out that he had a terminal illness that would bring him a lot of uffering in his final months. He got upset about dying - but that he couldn't do anything about, because everyone dies. But he got especially upset and scared about the fact that he is going to undergo a lot of suffering. So he decided to pay a visit to a very famous Rabbi-tzaddik and ask for his intercession with G-d. He travelled to his village, found his house, and knocked on the door. The Rebbetzin opens the door and asks him inside. When he is in the room, the Rebbetzin asks what his business is with the Rabbi. The man tells her about the diagnosis, and adds: "I just want the Rabbi to know that I am a good man. Everyone will attest to this. I have lead an upright life. I don't deserve so much suffering; it really scares me. I'd like to ask the Rabbi to pray for me so that my final days are not as terrible as the doctors predict. Allright, says the Rabbi's wife. I will go talk to my husband about this. In the meantime, sit down in this comfortable chair by the fireplace and rest.
The chair was indeed very comfortable, and the place by the fire very warm. Before he knew it, the man fell asleep and started dreaming. In his dream, he was already dead. He was brought to a place that looked like a courtroom. A very stern judge said that now all his deeds will be weighed. They brought in a large sack and dumped its contents onto one side of the scales, which plunged down immediately. "These are your bad deeds," said the judge. Then they brought a much smaller bag and told him that these were his good deeds. When they put it on the other side of the scales, the scales did not move. "Woe to me!" cried out the man, "I'm finished." But as soon as he said it, he saw that they were bringing out yet another bag. "What's in this bag?" he asked, surprised. "These are you sufferings," he was told. They untied the bag and started shaking its contents out onto the good-deed side. Very slowly the scales started to move. "More sufferings, more sufferings, bring on more sufferings," the man started screaming, very agitated. At this moment he felt somebody shaking his shoulder. He woke up and saw the Rabbi. "Did you just say that you wanted more sufferings?" asked the Rabbi. "Then you have changed your mind."