Having never used the spaceship operator.. I saw some code and asked a colleague. True enough being a perl programmer.. he said 'relative comparison'.
And google wasn't very helpful in finding the truth till I found this page :
http://dev.mysql.com/doc/refman/5.0/en/non-typed-operators.html
In sql, it is a null safe equality comparator.
i.e, instead of
tableName.columName == 10,
tableName.columName <=> 10 takes care of the fact that the record has a null value.
Hmm.. why not change the behaviour of '==' itself ?
In perl/ruby/groovy its a comparative operator - gives a 1, 0, -1 based on whether your first operand is greater, equal or less than the second operand.
ie:
1 when 6 <=>5
0 when 6 <=>6
-1 when 6 <=> 7
Wednesday, May 20, 2009
Subscribe to:
Comments (Atom)
