Updated

PHOENIX -- Paul Goldschmidt homered on his 30th birthday and J.D. Martinez went deep twice, helping Robbie Ray and the Arizona Diamondbacks beat the San Diego Padres 3-2 on Sunday to avoid a three-game sweep.

Martinez hit solo drives in the second and sixth innings, the latter breaking a 2-2 tie. He has reached safely in 14 straight games and has 37 home runs this season. He hit 16 in 57 games with Detroit and 21 in 45 games since Arizona acquired him. Six of Martinez's seven career multi-home run games have come this season, four with Arizona.

Ray (13-5) won his fourth straight start, striking out 12 in six innings while allowing two runs and four hits. Archie Bradley got the call over closer Fernando Rodney in the ninth and earned his first save this season by striking out the side.

Arizona remained five games ahead of second-place Colorado for the NL's top wild card.

Goldschmidt's 34th home run, his first since Aug. 30, gave the Diamondbacks a 2-1 lead in the fourth. Yangervis Solarte tied the score with a sacrifice fly in the sixth.

Luis Perdomo (7-10) gave up three runs and five hits in six innings.

Luis Torrens hit an RBI single in the second, a line drive that just missed Ray's head as the crowd groaned. Ray missed almost a month after being stuck by a line drive in late July.

Wil Myers struck out twice and raised his season total to 162, two more than the previous Padres record set by Mike Cameron in 2007.

CALL-UPS DELAYED

Padres manager Andy Green prefers to let potential call-ups stay with El Paso for the Triple-A postseason.

"We're of the belief that guys being on the field consistently is probably better than having them sit on the bench at the big-league level," Green said.

FIRST TIME FOR EVERYTHING

When Arizona wasted a 7-2 ninth-inning lead in an 8-7 loss Saturday night, it marked the first time the Diamondbacks lost with a lead of five or more runs entering the ninth, according to the Elias Sports Bureau. They had won their first 436 games in that situation. Four franchises remain that have not lost when entering the ninth ahead by five or more: the Marlins, Padres, Rangers and Rockies.

TRAINER'S ROOM

Diamondbacks: RHP Randall Delgado was placed on the 60-day DL with right elbow inflammation, and the club recalled INF-OF Christian Walker from Reno. Walker, the Pacific Coast League's MVP, pinch hit in the seventh inning and flied out. … Goldschmidt told manager Torey Lovullo he felt fine after playing Saturday, his first game after missing five with an elbow problem. . C Chris Iannetta got the day off, a little sore after being hit on an arm by a pitch Saturday.

Padres: Pirela appeared to hurt a hand sliding into third base in the sixth and was checked by a trainer but stayed in the game.

UP NEXT

Diamondbacks: RHP Zack Greinke (16-6) opens a four-game series against Colorado on Monday. He is 13-1 in 16 home starts this season.