David met Goliath yesterday, and was nearly beaten to death.

The giant took away his sling, battered his figures and his economic theory, and tried to go for his heart, but claimed it was nowhere to be found.

But David A. Stockman, 34-year-old director of the Office of Management and Budget, has survived many such encounters in recent weeks, and he survived this one with the House subcommittee on economic development.

Seldom has he found such an array of Republicans and Democrats allied against something he wants to do. Although much of the discussion was over economic theory, it really was a lesson in porkbarrel politics.

Stockman said he wants to "zero out" the Economic Development Administration (EDA) and the Appachian Regional Commission (ARC), two programs the subcommittee oversees, as part of the Reagan administration's budget-cutting effort. By Washington standards, they are pretty much small potatoes. Doing away with them would save $754 million this year.

Stockman's problem yesterday was that every member on the subcommittee has some EDA or ARC project back home dear to his heart.

As a reminder of this, scores of photographs of Duluth, Minn., in Chairman James L. Oberstar's (D) district, lined the hearing room. Duluth has received $20.4 million in grants from EDA and its predecessor, the Area Development Administration, since 1963.

Oberstar and other Democrats argued that the EDA is a rare federal program in that it "pays its own way." The chairman claimed that the $4.7 billion the agency has spent has spurred $9 billion in private investment and created 1.5 million jobs in depressed areas.

Stockman replied that this was "single-entry bookkeeping."

"EDA doesn't create jobs," he said, "it reallocates them." Later he said that "we have a great shell game going on where resources are moved around the country, but I'm not sure who is helped."

He argued that not only is the termination of the two programs necessary for President Reagan's economic plan to succeed, but it represents "a basic change in philosophy, a basic change in government policy. We believe government should get out of the regional-development and job-creation business."

Job development should be left to the free-market movement of the economy, he said repeatedly.

Few, even among the Republicans on the subcommittee, agreed. Many are from depressed areas with failing industrial bases. They cited projects from American Samoa to Paterson, N.J., as examples of EDA's good work.

"You seem concerned only about profits, and not about people," said Rep. Gus Savage (D-Ill.), adding later that Stockman's approach was the opposite of Robin Hood's in that "You're robbing the poor and giving to the rich."

Stockman said that an individual's commitment to the poor should not be judged "on how much he wants to spend on food stamps."

Rep. Tom Hagedorn (R-Minn.) offered one comment that seemed to please the budget director: "If Adam Smith were here, he'd be proud of you."