anns a’ mhargadh (the definite article in dative causes lenition), but yes, it would have to be anns + the article to mean in the….
ann an and ann am (before b, p, m, f) just means in. It is doubled in as originally in was just an or am, but at some point apparently that started becoming confusing and people started to double it. Instead of am margadh (either the market or in a market) people started saying ann am margadh (unambiguously there, in a market).
See more in the ann an article on Akerbeltz wiki.