Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id EF1AEB5DBF6 for ; Mon, 22 Aug 2011 10:27:20 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 73327-02 for ; Mon, 22 Aug 2011 13:27:14 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sam.nabble.com (sam.nabble.com [216.139.236.26]) by mail.postgresql.org (Postfix) with ESMTP id 81919B5DBDC for ; Mon, 22 Aug 2011 10:27:12 -0300 (ADT) Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1QvUX3-0005Sj-6N for pgsql-sql@postgresql.org; Mon, 22 Aug 2011 06:27:13 -0700 Date: Mon, 22 Aug 2011 06:27:13 -0700 (PDT) From: Enzen user To: pgsql-sql@postgresql.org Message-ID: <1314019633187-4723409.post@n5.nabble.com> Subject: sorting months according to fiscal year MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.778 tagged_above=-5 required=5 tests=BAYES_00=-1.9, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201108/84 X-Sequence-Number: 35752 Hi I have to rearrange the months according to the fiscal year i.e from April to march and use the same in the order by clause of a query. I have written the following postgresql function for the same, but to_number is returning an error. Can you please tell me where i'm going wrong? Instead of the function to_number can you suggest any other function that will convert a particular month to its corresponding month number(ex: april=4 or jan=1) CREATE FUNCTION sort_month(to_number('April','MM')) RETURNS numeric AS $$ DECLARE BEGIN CASE WHEN 4 THEN 1 WHEN 5 THEN 2 WHEN 6 THEN 3 WHEN 7 THEN 4 WHEN 8 THEN 5 WHEN 9 THEN 6 WHEN 10 THEN 7 WHEN 11 THEN 8 WHEN 12 THEN 9 WHEN 1 THEN 10 WHEN 2 THEN 11 WHEN 3 THEN 12 ELSE 0 END; $$ LANGUAGE plpgsql; -- View this message in context: http://postgresql.1045698.n5.nabble.com/sorting-months-according-to-fiscal-year-tp4723409p4723409.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.