Search This Blog

Tuesday, February 9, 2010

sorting in postgresql


When I was working on a query I wrongly typed the where condition as order by then i found it accepts and gives result by sorting on the order of values i have given check below , We can use this cool feature for sorting columns like month week days etc., instead of storing print order we can use this (after checking the performance factor)
Example : 

SELECT leather_type_id as a,leather_type_name from _mleather_type order by leather_type_id in (200795,200794,200796) desc;
   a    | leather_type_name
--------+-------------------
 200795 | Goat
 200796 | Pig
 200794 | Cow
 200797 | Sheep
 202082 | Reptile
 200190 | Hair Sheep
 203319 | touchleather
 203320 | cow touch leather
 200193 | Others
 200793 | Buffalo

No comments:

Post a Comment