JACK WARNER would never have cast him for the part. It was Mr. Warner who, when asked whether he liked Ronald Reagan for governor, is supposed to have said, "No. Jimmy Stewart for governor. Ronny for best friend." Mr. Reagan, as it turned out, was not so badly miscast for the role as to be unable to win a real-life election. Edward Koch, as it turned out in Thursday's New York Democratic primary, was.

That is the major reason for Mr. Koch's upset defeat. Ed Koch is as popular a mayor of New York as the city has had since the first term of Robert Wagner or the last of Fiorello LaGuardia. He is popular partly because the public approves of his policies, which include a tough approach to crime, a firm opposition to racial and ethnic quotas and a determination to force the city's public employees to live within the taxpayers' means. But his popularity also rests on the fact that he is a kind of quintessential New Yorker. He first came to the public attention as the representative of reform Democrats in the nation's first trendy neighborhood, Greenwich Village. But it became clear, as he ran for mayor in 1977, that he was still the boy who grew up on the gritty streets of Brooklyn. He is street smart as well as book smart, a lofty orator who delights in giving his adversaries the raspberry.

So it was not uncharacteristic for Mr. Koch to have told a Playboy magazine interviewer that rural life is "a joke" and that suburban life is "sterile, wasting your life." It was unfortunate for his campaign that the piece appeared just after he reconsidered his longtime determination to run for no office higher than mayor and had begun seeking the Democratic nomination for governor. His popularity for mayor seemed to many to guarantee him victory in a contest in which most votes were cast by New York City residents. But apparently many New Yorkers wanted to keep him where he was. In a graceful concession speech, Mr. Koch said, "I have no regrets. I'm still the mayor and that's not bad. In fact, it's good." Voters have a more sophisticated sense than is generally realized about the different requirements of different public offices. In this case, New York's Democrats seem to have made a shrewd decision, as Jack Warner would. No. Mario Cuomo for governor. Ed Koch for mayor.