Gandhi’s admirers perform all sorts of rhetorical contortions to defend some of his more bizarre ideas and practices. One such practice that became public knowledge in the twilight of his life shocked even his most dyed-in-wool devotees.
On the eve of Independence, Gandhi marched through the paddy fields of Bengal on foot with a wooden staff and a train of followers to calm seething Hindu-Muslim hostility with nothing more than the sheer force of his personality. A mobile toilet carried by his admirers along with the more familiar Gandhian prop, the spinning wheel, accompanied the great man during this celebrated journey.
It was during this time that one of Gandhi’s more controversial practices became public knowledge. Ostensibly to test his long-standing vow of brahmacharya (celibacy), Gandhi was found to be in the habit of sharing his bed with young women.
There is no suggestion that Gandhi in any way violated his sleeping partners, many of whom selflessly ministered to his physical well-being and acted as his confidantes. However, the incongruity of the old, ascetic Gandhi sleeping naked with young women scandalised the sensibilities of his puritanical Hindu followers as well as those of more secular bent in the Congress Party.
Gandhi’s achievement in Bengal that year turned out to be nothing short of miraculous. While Punjab and the rest of the Subcontinent was seized by collective madness, with Hindus and Muslims indulging in an orgy of tit-for-tat murders that ultimately claimed millions of lives, Bengal held its peace thanks only to Gandhi’s commanding presence and towering moral authority.
Gandhi camped with his followers in an old, decaying bungalow in a Muslim neighbourhood in Calcutta as Hindu-Muslim tensions threatened to boil over. A Muslim mob moved into the neighbourhood and started to attack Gandhi, hurling stones and abuses and ordering him to move out. Gandhi pacified and won over his attackers by declaring that he would not leave the place as long as a single Muslim in the neighbourhood felt threatened and insecure from Hindus.
Some of Gandhi’s ideas about social reform, such as his rejection of industrialisation in favour of an agrarian utopia that supposedly existed in India’s imagined past or his re-categorization of the Hindu untouchables into ‘Harijans’ (God's people), can be charitably dismissed as quixotic or misguided. If only deep-rooted social evils such as the Hindu caste system could be magically eradicated by re-labelling its victims!
However, Gandhi’s lifelong struggle against injustice and colonialism, first in South African and then in India, justifies his undisputed standing as a giant of the 20th century.
As the British broadcaster Mishal Husain argued in a recent three-part BBC documentary, Gandhi’s admirers do him a great disservice by placing him on a pedestal.
A Gandhian female academic that Husain interviewed in India for the documentary was asked about Gandhi’s controversial practice of sleeping naked with his young female followers.
Instead of admitting the possibility that Gandhi, Mahatma though he was, could have made errors of judgement, the academic trotted out the familiar argument about Gandhi testing his resolve and self-control by sleeping with nubile women. Even more disingenuously, she claimed the women would have been enriched morally by the experience notwithstanding the fact that Gandhi used them as mere foil to his dubious spiritual exercises. In his followers’ eyes, Gandhi could do no wrong and was above reproach.
What if the Mahatma had lost his self-control?
But if we forget Gandhi the legend, there is a lot to like about the man.
Though many know that Gandhi sought solace and inspiration in the ancient verses of the Hindu scripture Geeta, few are aware of the eclectic influences of his youth that shaped his mature worldview.
While studying law in London, he read Geeta for the first time. However, he also read the Sermon on the Mount and Tolstoy, and socialised with Theosophists and London’s vegetarians, giving up meat.
He sailed to London despite threats from his clan elders to strip him of his caste status and its attendant privileges. By sailing to London, Gandhi violated the ancient Hindu taboo against crossing seas. His later attempts to recover his caste status by performing prescribed ceremonies failed, apparently because his clan elders had not forgiven his transgression.
He cut his political teeth by fighting racism against Indians and blacks in South Africa. He mobilised the Indian mass against the British Empire on the principle of non-violence and succeeded to wrest freedom for them.
Just before and in the aftermath of Independence, Gandhi protected Muslim minorities and their properties from murderous Hindu mobs, first in Bengal and then in New Delhi. He paid for his ecumenicalism and vision of universal brotherhood with his life at the hand of a Hindu fanatic.
Gandhi’s puritanism and bizarre spiritual experiments in old age, his insistence on interfaith goodwill to address Muslim minority concerns in place of concrete political concessions, his refusal to support any special treatment to Hindu outcasts, his uncritical apotheosis in modern India, and his stern gaze from the pedestal can be quite off-putting.
However, bring him down from the pedestal and Gandhi, with or without his loincloth, starts to look much more attractive.
Monday, February 14, 2011
Sunday, January 16, 2011
Institutions Matter
Why is it that some countries continue to be poor despite being blessed with abundant natural resources, human capital and technology transfer from developed countries? Many resource-rich African countries mired in poverty and bloody civil wars come to mind. Even India, despite its much lauded economic growth of recent years, can be added to the list of these underachievers.
According to Tim Harford in The Undercover Economist (2006), the answer lies in the poor nations' institutions or lack thereof. As he puts it succinctly, "institutions matter".
Most resource-rich poor countries lack institutions capable of holding executive power in check and making them accountable to the people. As a result, the ruling cliques and their cronies can cream off the proceeds from the resources with impunity and become obscenely rich while the vast majority of their compatriots sink deeper into poverty.
"Institutions matter". This phrase popped into my mind again when reading about the 1843 British annexation of Sindh (Punjab) in John Keay's India: A History (2000). One of the last so-called princely states to be bullied into Pax Britannica, Sindh had been able to keep the British at bay with diplomacy and a modern military under the inspired rule of Maharaja Ranjit Singh.
On the eve of the First British Afghan War in which the British Raj suffered one of its most disastrous losses, Ranjit Singh, the Bonaparte of Sindh, the Lion of Punjab, died, in 1839.
Keay writes: "A philander of many wives and more women, he was not without potential successors. Yet so personal had been his rule and so absolute his authority that the institutions of sovereignty and government through which a successor might establish himself scarcely existed."
The result was predictable. In the midst of the succession crisis that engulfed Sindh, the British, in the words of the victorious British general, pulled off a "very advantageous, useful, humane piece of rascality."
'Rascality' actually sums up the Indian, or perhaps any human, history.
Keay opens his narrative with the ancient Indian concept of Matsya-Nyaya or 'fish law' according to which big fish devour small fish. The subsequent laundry list of dynasties great and small that subjugate various parts of the Indian sub-continent through the millennia appears like a rogue’s gallery of history.
When the various dynasties are not oppressing their wretched subjects by imposing extortionate taxes to finance their ego-boosting monumental extravagances, they are at each others' throats, pillaging the defeated kingdoms’ treasuries and polluting their women.
This gives lie to the myth of a golden age, the so-called ‘Ram Rajya’, to which many people of certain persuasion look back with great nostalgia in the Indian sub-continent.
Keay has a slippery grasp of Sanskrit words and phrases but he, nevertheless, convincingly demolishes many cherished mytho-historical sacred cows of India. For example, he cogently argues that the epic Mahabharata predates Ramayana, a startling proposition only an outsider like Keay could perhaps make.
After reading about the umpteenth petty cutthroat performing a ritual digvijaya or world conquest and assuming the title of Maharajadhiraja , one starts to contemplate the august personages of surviving Maharajadhirajas with fresh eyes.
According to Tim Harford in The Undercover Economist (2006), the answer lies in the poor nations' institutions or lack thereof. As he puts it succinctly, "institutions matter".
Most resource-rich poor countries lack institutions capable of holding executive power in check and making them accountable to the people. As a result, the ruling cliques and their cronies can cream off the proceeds from the resources with impunity and become obscenely rich while the vast majority of their compatriots sink deeper into poverty.
"Institutions matter". This phrase popped into my mind again when reading about the 1843 British annexation of Sindh (Punjab) in John Keay's India: A History (2000). One of the last so-called princely states to be bullied into Pax Britannica, Sindh had been able to keep the British at bay with diplomacy and a modern military under the inspired rule of Maharaja Ranjit Singh.
On the eve of the First British Afghan War in which the British Raj suffered one of its most disastrous losses, Ranjit Singh, the Bonaparte of Sindh, the Lion of Punjab, died, in 1839.
Keay writes: "A philander of many wives and more women, he was not without potential successors. Yet so personal had been his rule and so absolute his authority that the institutions of sovereignty and government through which a successor might establish himself scarcely existed."
The result was predictable. In the midst of the succession crisis that engulfed Sindh, the British, in the words of the victorious British general, pulled off a "very advantageous, useful, humane piece of rascality."
'Rascality' actually sums up the Indian, or perhaps any human, history.
Keay opens his narrative with the ancient Indian concept of Matsya-Nyaya or 'fish law' according to which big fish devour small fish. The subsequent laundry list of dynasties great and small that subjugate various parts of the Indian sub-continent through the millennia appears like a rogue’s gallery of history.
When the various dynasties are not oppressing their wretched subjects by imposing extortionate taxes to finance their ego-boosting monumental extravagances, they are at each others' throats, pillaging the defeated kingdoms’ treasuries and polluting their women.
This gives lie to the myth of a golden age, the so-called ‘Ram Rajya’, to which many people of certain persuasion look back with great nostalgia in the Indian sub-continent.
Keay has a slippery grasp of Sanskrit words and phrases but he, nevertheless, convincingly demolishes many cherished mytho-historical sacred cows of India. For example, he cogently argues that the epic Mahabharata predates Ramayana, a startling proposition only an outsider like Keay could perhaps make.
After reading about the umpteenth petty cutthroat performing a ritual digvijaya or world conquest and assuming the title of Maharajadhiraja , one starts to contemplate the august personages of surviving Maharajadhirajas with fresh eyes.
Labels:
Books,
chess,
History,
Indian history,
institutions,
maharajas,
mughals,
Non-Fiction,
Pax Britannica,
Raj
Sunday, January 2, 2011
How Many Springs Do We See?
Pear blossoms pale white, willows deep green,When willow fluff scatters, falling petals will fill the town,Snowy boughs by the eastern palisade set me pondering -In a lifetime, how may springs do we see?
Friday, December 31, 2010
Five Books That I Enjoyed Reading in 2010
The followings were the five books that I enjoyed reading most in 2010:
Special mention goes to Pride and Prejudice by Jane Austen. It happened to be the first book that I read in EPUB format on a mobile device.
- Dreams From My Father by Barack Obama
- The Black Swan: The Impact of the Highly Improbable by Nassim Nicholas Taleb
- The Girl with the Dragon Tattoo by Stieg Larsson
- 3:59.04: The Global Quest to Break the 4 Minute Mile by John Bryant.
- The Best Australian Essays 2010 edited by Robert Drewe
Special mention goes to Pride and Prejudice by Jane Austen. It happened to be the first book that I read in EPUB format on a mobile device.
Labels:
Barack Obama,
Black Swan,
Books,
EPUB,
Steig Larsson
Thursday, December 30, 2010
The Banyan Tree of Limbus
On Christmas Day, a couple of Limbu friends favored us with a visit to our place at Kogarah, and, over orange juice and canapes, we discussed the consanguinity taboos that govern Limbu marriages. My friend's spouse pointed out that if the consanguinity taboos were observed strictly, a Limbu lad or lash would find it difficult to find a suitable match.
The Limbu marriage code forbids two types of marriages on consanguinity grounds. First, marriages between parties having same surnames are proscribed in most cases. I said "most cases". For example, my mother's Limbu surname is "Menyangbo", and, as far as I know, a Menyangbo cannot wed another Menyangbo.
My own Limbu surname is "Thebe". Thebes are further sub-divided into "Thupukko", "Sing" and "Maabo". A union between a Thupukko Thebe such as myself and a Sing Thebe is legitimate but not, as far as I know, between other Thebe sub-types. This inconsistency betrays the somewhat arbitrary, malleable nature of this particular taboo, and may suggest that Sing Thebes were once a distinct clan who were assimilated by the numerically superior Thebes at some point in history.
Local legend has this to say about the origins of Sing Thebes: The first Sing Thebe was a Thupukko Thebe who went foraging for firewood in the forest and got lost. So, he became Sing or "Firewood" Thebe. This legend is a warning to any future Sing Thebe genealogist tempted to find false glory by tracing their roots to the "Singhs" of North India. Bull dust such as "Sing Thebes descended from Rajput kings of North India who fled the bountiful plains of Rajasthan after losing a bloody palace power struggle and hid in the forested eastern foothills of what is now Nepal. The defeated royal warriors took Thebe girls for wives and concubines and, in time, their descendants combined the hallowed surnames of their royal ancestors and tribal mothers to emerge as Sing Thebes" should be left to the fawning astrologers of the now defunct courts of pompous Shahs and Ranas. But I digress.
The second type of marriage forbidden by Limbu tradition is between parties separated by up to five (some say nine) degrees of consanguinity. The definition and degree of consanguinity as understood and practiced by the Limbus is different to those of other groups within Nepal such as Magars, Gurungs and Ranas and those of Europeans.
Let us imagine a Thebe lad named Kaanden who is scanning a mental list of prospective brides. Since he is a Thebe, all Thebe girls anywhere except Sing Thebes are classed as Chelis (sisters) and expected to be treated as such. Even flirting and minor indiscretions (surely an oxymoron) with these Thebe girls would be strictly forbidden and attract severe consequences. In olden times, this basically meant the collective loss of face of the offender's extended family, blood feuds with the girl's own extended family, and the banishment of the offender into "Munglan", the land of the Mughals, i.e. India and Sikkim.
Let us imagine that our would-be bridegroom's mother is a Menyango. According to Limbu practice, this places the set of all Menyango girls at a distance of one degree of consanguinity. They are off limits to Kaanden and as sacred as his own mother.
Kaanden's paternal grandmother was a Maaden and maternal grandmother a Jabegu. So, any union with Maaden and Jabegu girls would be illicit as they are just two degrees removed, and, yes, Kanden needs to pay the same degree of respects to these girls as due to his own grandmothers. In fact, the prescribed way for Kanden to address these girls is as "grannies".
Kaanden's paternal grandfather's mother was a Lingden and maternal grandfather's mother a Chongbang. This means all Lingden and Chongbang girls are only three degrees removed and out of Kaanden's matrimonial calculus.
This hypothetical case illustrates the complexity of the web of clans that a Limbu has to negotiate to properly observe marriage taboos. Without getting lost in the forest of Kaanden's ancestral extended family, the number of clans, here loosely equated with major surname groups, excluded from Kaanden's marriage suit equals 32. Thirty-two! If nine degrees of consanguinity were to be observed, as is sometimes claimed, this number shoots up to 512. Are there even this many Limbu clans?
In practice, though, I suspect that even five degrees of consanguinity was always maintained on the female, the so-called 'leaf', sides of the family, branching off from mother, grandmother, great grandmother, etc. Though the Limbus have their own script, mass literacy is still a work in progress, and, in the absence of written records, folk memory can retain only so much information.
Late in the afternoon on the Christmas Day, we, along with our visiting friends, drove to a small park in Marrickville, an inner west suburb of Sydney, to mark the rite of passage of a Limbu friend's 10-month-old son. As many as 70-80 Limbus from various parts of the Limbuwan in eastern Nepal had flocked there. I suspect that if we all had taken the trouble to introduce ourselves and map our family trees, most of us would have found some common branches in our family trees, making most of us related by blood as per Limbu tradition.
The Limbu marriage code forbids two types of marriages on consanguinity grounds. First, marriages between parties having same surnames are proscribed in most cases. I said "most cases". For example, my mother's Limbu surname is "Menyangbo", and, as far as I know, a Menyangbo cannot wed another Menyangbo.
My own Limbu surname is "Thebe". Thebes are further sub-divided into "Thupukko", "Sing" and "Maabo". A union between a Thupukko Thebe such as myself and a Sing Thebe is legitimate but not, as far as I know, between other Thebe sub-types. This inconsistency betrays the somewhat arbitrary, malleable nature of this particular taboo, and may suggest that Sing Thebes were once a distinct clan who were assimilated by the numerically superior Thebes at some point in history.
Local legend has this to say about the origins of Sing Thebes: The first Sing Thebe was a Thupukko Thebe who went foraging for firewood in the forest and got lost. So, he became Sing or "Firewood" Thebe. This legend is a warning to any future Sing Thebe genealogist tempted to find false glory by tracing their roots to the "Singhs" of North India. Bull dust such as "Sing Thebes descended from Rajput kings of North India who fled the bountiful plains of Rajasthan after losing a bloody palace power struggle and hid in the forested eastern foothills of what is now Nepal. The defeated royal warriors took Thebe girls for wives and concubines and, in time, their descendants combined the hallowed surnames of their royal ancestors and tribal mothers to emerge as Sing Thebes" should be left to the fawning astrologers of the now defunct courts of pompous Shahs and Ranas. But I digress.
The second type of marriage forbidden by Limbu tradition is between parties separated by up to five (some say nine) degrees of consanguinity. The definition and degree of consanguinity as understood and practiced by the Limbus is different to those of other groups within Nepal such as Magars, Gurungs and Ranas and those of Europeans.
Let us imagine a Thebe lad named Kaanden who is scanning a mental list of prospective brides. Since he is a Thebe, all Thebe girls anywhere except Sing Thebes are classed as Chelis (sisters) and expected to be treated as such. Even flirting and minor indiscretions (surely an oxymoron) with these Thebe girls would be strictly forbidden and attract severe consequences. In olden times, this basically meant the collective loss of face of the offender's extended family, blood feuds with the girl's own extended family, and the banishment of the offender into "Munglan", the land of the Mughals, i.e. India and Sikkim.
Let us imagine that our would-be bridegroom's mother is a Menyango. According to Limbu practice, this places the set of all Menyango girls at a distance of one degree of consanguinity. They are off limits to Kaanden and as sacred as his own mother.
Kaanden's paternal grandmother was a Maaden and maternal grandmother a Jabegu. So, any union with Maaden and Jabegu girls would be illicit as they are just two degrees removed, and, yes, Kanden needs to pay the same degree of respects to these girls as due to his own grandmothers. In fact, the prescribed way for Kanden to address these girls is as "grannies".
Kaanden's paternal grandfather's mother was a Lingden and maternal grandfather's mother a Chongbang. This means all Lingden and Chongbang girls are only three degrees removed and out of Kaanden's matrimonial calculus.
This hypothetical case illustrates the complexity of the web of clans that a Limbu has to negotiate to properly observe marriage taboos. Without getting lost in the forest of Kaanden's ancestral extended family, the number of clans, here loosely equated with major surname groups, excluded from Kaanden's marriage suit equals 32. Thirty-two! If nine degrees of consanguinity were to be observed, as is sometimes claimed, this number shoots up to 512. Are there even this many Limbu clans?
In practice, though, I suspect that even five degrees of consanguinity was always maintained on the female, the so-called 'leaf', sides of the family, branching off from mother, grandmother, great grandmother, etc. Though the Limbus have their own script, mass literacy is still a work in progress, and, in the absence of written records, folk memory can retain only so much information.
Late in the afternoon on the Christmas Day, we, along with our visiting friends, drove to a small park in Marrickville, an inner west suburb of Sydney, to mark the rite of passage of a Limbu friend's 10-month-old son. As many as 70-80 Limbus from various parts of the Limbuwan in eastern Nepal had flocked there. I suspect that if we all had taken the trouble to introduce ourselves and map our family trees, most of us would have found some common branches in our family trees, making most of us related by blood as per Limbu tradition.
Tuesday, December 21, 2010
The Mythical Man-Month: Project Management Insights
Frederick Brooks, Jr’s software project management classic, The Mythical Man-Month (The MM-M), continues to be read, debated and entrenched in undergraduate reading lists thirty-five years after its publication. This is surprising in a field where 20 percent of current knowledge is estimated to become obsolete every 12 to 18 months.
To put things in perspective, when the book was first published, computer memory rented at USD12.00 per kilobyte per month. At that rate, the 32GB SD card in my Samsung Galaxy S would have cost over 400 million dollars per month.
One of the reasons behind the enduring popularity of The MM-M is the author’s premise that “managing a software project is more like other management than most ... initially believe”. Brooks, who earned his stripes as the Project Manager for the IBM System/360 computer family and its software, advances “propositions” that would be applicable in almost any non-trivial project, repeatedly hammering the point that project management is about people and teams, not technology.
He buttresses his propositions with war stories drawn from his IBM experience and other contemporary projects. Little wonder, then, that The MM-M continues to attract a motley readership comprising doctors, psychologists, sociologists, lawyers as well as IT professionals.
What are Brooks’ project management insights that have withstood the test of time and continue to be relevant in the new century? Here are some randomly selected teasers from the book, in quotes when copied verbatim, with my own comments in square brackets:
To put things in perspective, when the book was first published, computer memory rented at USD12.00 per kilobyte per month. At that rate, the 32GB SD card in my Samsung Galaxy S would have cost over 400 million dollars per month.
One of the reasons behind the enduring popularity of The MM-M is the author’s premise that “managing a software project is more like other management than most ... initially believe”. Brooks, who earned his stripes as the Project Manager for the IBM System/360 computer family and its software, advances “propositions” that would be applicable in almost any non-trivial project, repeatedly hammering the point that project management is about people and teams, not technology.
He buttresses his propositions with war stories drawn from his IBM experience and other contemporary projects. Little wonder, then, that The MM-M continues to attract a motley readership comprising doctors, psychologists, sociologists, lawyers as well as IT professionals.
What are Brooks’ project management insights that have withstood the test of time and continue to be relevant in the new century? Here are some randomly selected teasers from the book, in quotes when copied verbatim, with my own comments in square brackets:
- The Biblical Tower of Babel project failed due to communication issues
- “... the essential problem [in project management] is communication”
- “The crucial task is to get the product defined. Many, many failures concern exactly those aspects that were never quite specified.”
- “... adding manpower to a late software project makes the project later”
- “... conceptual integrity is the most important consideration in system design” [or project]
- “Organizations which design systems are constrained to produce systems which are copies of the communication structures of these organizations”
- “The [project] manager will be continually amazed that policies he [sic] took for common knowledge are totally unknown by some member of his team”
- “The total cost of maintaining a widely used program is typically 40 percent or more of the cost of developing it. Surprisingly, this cost is strongly affected by the number of users. More users find more bugs.”
- “The fundamental problem with program maintenance is that fixing a defect has a substantial (20-50 percent) chance of introducing another”
- “Many poor systems come from an attempt to salvage a bad basic design and patch it with all kinds of cosmetic relief.”
- “How does a project get to be a year late? ... One day at a time”
- “When one hears of disastrous schedule slippage in a project, he images that a series of major calamities must have befallen it. Usually, however, the disaster is due to termites, not tornadoes ... ” [As the saying goes, for want of a nail, the kingdom was lost]
- “I believe the hard part of building software to be the specification, design and testing of this conceptual construct, not the labor of representing it and testing the fidelity of the representation.” [author’s emphasis. He means coding by ‘representing’. The author contends that fidelity to specification is pointless if the specification itself is flawed]
- “The hardest single part of building a software system is deciding precisely what to build ... For the truth is, the clients do not know what they want ... So ... it is necessary to allow for extensive iteration between the client and the designer as part of the system definition.”
- “In my experience most of the complexities which are encountered in systems work are symptoms of organizational malfunction. Trying to model this reality with equally complex programs is actually to conserve the mess instead of solving problems”
- “Chemical engineers have learnt not to take a process from the lab bench to the factory in one step, but to build a pilot plant to give experience in scaling quantities up and operating in non-protective environments.” [author’s emphasis]
- “The second [project] is the most dangerous system a person ever designs; the general tendency is to overdesign it ... using all the ideas and frills that were cautiously sidetracked on the first one.”
- “My rule of thumb is 1/3 of the schedule for design, 1/6 for coding, 1/4 for component testing, and 1/4 for system testing” [This means testing should be assigned half the schedule time. Coding gets the least amount of time]
- “Schedule disaster, functional misfit, and system bugs all arise because the left hand doesn’t know what the right hand is doing. Teams drift apart in assumptions.”
Labels:
Books,
management,
mythical,
Non-Fiction,
project,
software
Saturday, December 18, 2010
Deconstructing an SQL snippet
Recently, I came across the following snippet in a Teradata SQL script that came my way:
I knew that Teradata, just like Excel, internally saves dates as integers but did not remember the conversion scheme. A quick search later, I had the formula:
Integer Date = (YEAR – 1900) * 10000 + (MONTH * 100) + DAY
So, Teradata internally saves today’s date, i.e. 2010-12-18, as 1101218. Here, year = 110 (110 years since 1900), month = 12 and day = 18.
Now, it was just a matter of taking the expressions apart piece by piece, starting from the innermost expressions.
In the line “(((ADD_MONTHS(DATE,-1)) /100 ) *100 +1) (DATE)”, the function ADD_MONTHS(DATE, -1) is merely adding -1 month to today’s date. Since today is 2010-12-18, the function returns 2010-11-18. It’s internally saved as 1101118.
The result of ADD_MONTHS(), 1101118, is divided by 100. This is an ‘integer’ division and results in 11011. The division removes the day part. If one tries to cast this number to date, Teradata complains, predictably.
In the next step, 11011 is multiplied by 100 to restore the day part, resulting in 1101100. However, there is something seriously wrong with 1101100 as it has ‘00’ for day part, which is illegal. This is why 1 is added to the result of (ADD_MONTHS(DATE,-1)) /100 ) *100 to give the first day of the previous month. The final '(DATE)' merely casts the integer to date.
So, all that the expression “(((ADD_MONTHS(DATE,-1)) /100 ) *100 +1) (DATE)” is doing is calculating the first day of the previous month. Similarly, the expression “( ( (((ADD_MONTHS(DATE,-0)) /100 ) *100 +1) (DATE) ) -1) (DATE)” calculates the last day of the previous month. It first calculates the first day of the current month and subtracts 1 day from it, which results in the last day of the previous month. (The ADD_MONTHS() function is redundant in the second expression as it is basically doing nothing except confound users).
Coincidentally, I had previously written a more intuitive way of achieving the same result. It has the virtue of not using magic numbers:
select calendar_date
from sys_calendar.calendar
where Calendar_Date Between
(((ADD_MONTHS(DATE,-1)) /100) *100 +1) (DATE)
AND (((((ADD_MONTHS(DATE,-0)) /100 ) *100 +1) (DATE)) -1) (DATE);
I knew that Teradata, just like Excel, internally saves dates as integers but did not remember the conversion scheme. A quick search later, I had the formula:
Integer Date = (YEAR – 1900) * 10000 + (MONTH * 100) + DAY
So, Teradata internally saves today’s date, i.e. 2010-12-18, as 1101218. Here, year = 110 (110 years since 1900), month = 12 and day = 18.
Now, it was just a matter of taking the expressions apart piece by piece, starting from the innermost expressions.
In the line “(((ADD_MONTHS(DATE,-1)) /100 ) *100 +1) (DATE)”, the function ADD_MONTHS(DATE, -1) is merely adding -1 month to today’s date. Since today is 2010-12-18, the function returns 2010-11-18. It’s internally saved as 1101118.
The result of ADD_MONTHS(), 1101118, is divided by 100. This is an ‘integer’ division and results in 11011. The division removes the day part. If one tries to cast this number to date, Teradata complains, predictably.
In the next step, 11011 is multiplied by 100 to restore the day part, resulting in 1101100. However, there is something seriously wrong with 1101100 as it has ‘00’ for day part, which is illegal. This is why 1 is added to the result of (ADD_MONTHS(DATE,-1)) /100 ) *100 to give the first day of the previous month. The final '(DATE)' merely casts the integer to date.
So, all that the expression “(((ADD_MONTHS(DATE,-1)) /100 ) *100 +1) (DATE)” is doing is calculating the first day of the previous month. Similarly, the expression “( ( (((ADD_MONTHS(DATE,-0)) /100 ) *100 +1) (DATE) ) -1) (DATE)” calculates the last day of the previous month. It first calculates the first day of the current month and subtracts 1 day from it, which results in the last day of the previous month. (The ADD_MONTHS() function is redundant in the second expression as it is basically doing nothing except confound users).
Coincidentally, I had previously written a more intuitive way of achieving the same result. It has the virtue of not using magic numbers:
SELECT CALENDAR_DATE
FROM SYS_CALENDAR.CALENDAR
WHERE CALENDAR_DATE BETWEEN
ADD_MONTHS(CURRENT_DATE, -1) - EXTRACT(DAY FROM CURRENT_DATE) + 1
AND CURRENT_DATE - EXTRACT(DAY FROM CURRENT_DATE);
Subscribe to:
Posts (Atom)