I remember once, when on a visit to Amsterdam, I noticed in one of its narrower streets a church and a brothel so closely opposed to each other that I could just about have stood with one foot in the knocking-shop's doorway and the other in the church's. I wondered how the ecclesiastical authorities, even in such a liberal-minded country, could have accommodated such proximity.

Well, now I know: because there have been links between the church and prostitution since well before Christian times. And in Christian times, even the church's famously anti-sex attitude led, paradoxically, to some strange and striking compromises; for example, there were prostitutes in 15th-century Strasbourg, known as "swallows", who worked in the cathedral's bell tower; in 1608, the Dominicans of Perpignan "collected alms from their congregations for the refurbishment of the order's bordello". These are, though, by no means the weirdest parts of Berkowitz's extraordinary book. We begin, as all histories of human civilisation must, in ancient Mesopotamia, where we learn that, pace Lévi-Strauss, incest is not the universal taboo we hold it to be. In Egypt, the practice was so encouraged that you could actually get into trouble if you didn't marry your sister. It took the Romans three centuries to eradicate the custom.

When something as irrational as sex comes up against something as self-proclaimedly "rational" (ha!) as the law, then the law is going to be made to look pretty silly: that is the underlying message of this book. Not that this would be any comfort to you if, say, you were about to be severely punished for the crime of having been raped, as was not only common across much of the world for millennia, but persists today in those parts still governed by bigotry and religious mania. It is funny, but quietly instructive, how those most exercised about the sexual incontinence of others go to such great lengths to seek it out or incite it, as a quick look at the methods of the 19th-century Society for the Suppression of Vice would quickly confirm.

Berkowitz, a lawyer-cum-journalist, has used both his skills to extremely good effect. This is a book that could so easily have been either too smirkingly knowing or too dry. Early on, when comparing Mosaic law with that of the earlier Middle Assyrians, and noting almost identical concern about what should happen if a woman attacks a man's balls when fighting, Berkowitz observes that Deuteronomy was not necessarily dictated by God, but that "it appears that this Hebrew law was a reflection of a regional testicle fixation". On almost every page, Berkowitz is prompted to make some similar droll comment, and here's the clever part: it is never done inappropriately or facetiously. Somehow he always gets the tone right. "The only weapon against genital demands was moral will," he writes of Augustine's teachings regarding sex, "but the smart money was always on the gonads." Even when one has all the information at one's disposal, laughter is an excellent way of getting the information to sink in.

And there is much to laugh at; otherwise we'd be weeping at the injustice of it all. Berkowitz's legal background would appear to have helped him churn through millennia of documents, from the days of cuneiform to the 20th century (where he stops: the noise of the present would drown out the past, he says; and there are plenty of examples which shed light on the idiocies and inconsistencies of today). I don't think I've ever read such an entertaining historical work. It has the wisdom granted by perspective, without the condescension of someone who thinks we're wiser than our ancestors. Whether you want to fuel your indignation, or simply furnish yourself with enough jaw-dropping data to galvanise a hundred party conversations ("Did you know that the single event that precipitated the fall of the Roman empire more than any other was the imprisonment of a popular homosexual charioteer in Thessalonica in 390AD?"), you really must shell out for this book. It's worth every penny..