TORONTO (Reuters) - Canada's main stock index ended lower on Wednesday, hurt by losses among miners with weaker copper and gold prices, a pullback in technology stocks led by Shopify Inc and a fall in shares of Canadian National Railway Co (>> Canadian National Railway Company).

Better-than-expected quarterly earnings boosted Royal Bank of Canada (>> Royal Bank of Canada), the country's largest bank by market value, while several other heavyweight financial stocks also gained.

* The Toronto Stock Exchange's S&P/TSX composite index <.GSPTSE> ended down 61.92 points, or 0.39 percent, at 15,967.72. Seven of the index's 10 main sectors finished lower, with three decliners for every two advancers overall.

* CN Rail fell as much as 4.9 percent, to its lowest level since March, before recovering somewhat to end down 1.8 percent at C$98.20. That was its worst one-day fall since July 26.

* CN Rail's chief financial officer said its fourth quarter may be a "bit more difficult" because of an early winter and a couple of derailments.

* Royal Bank of Canada (>> Royal Bank of Canada) gained 0.9 percent to C$101.38, while the overall financial sector rose 0.4 percent.

* Shopify Inc fell 7 percent to C$133.40, erasing gains the e-commerce software company's stock had made after the Black Friday and Cyber Monday shopping days. The technology group fell 2.6 percent overall.

* The materials group, which includes precious and base metals miners and fertilizer companies, lost 1.3 percent as prices for gold as well as copper, aluminum and other base metals fell.

* Potash Corp (>> Potash Corporation of Saskatchewan Inc) added 0.6 percent to C$25.08 after its chief executive said he expects a "very tight" balance of potash supply and demand in 2018 and that the company had received "broad interest" from Chinese buyers interested in its stake in a Chilean lithium producer.

(Reporting by Alastair Sharp; editing by Jonathan Oatis and Grant McCool)

By Alastair Sharp