pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Enzen user <anushka.achaiah@enzentech.com>
To: pgsql-sql@postgresql.org
Subject: sorting months according to fiscal year
Date: Mon, 22 Aug 2011 06:27:13 -0700 (PDT)
Message-ID: <1314019633187-4723409.post@n5.nabble.com> (raw)

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.ht...
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.



view thread (3+ messages)  latest in thread

Message-ID: <1314019633187-4723409.post@n5.nabble.com>
Permalink:  ../1314019633187-4723409.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1314019633187-4723409.post@n5.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: anushka.achaiah@enzentech.com
  Subject: Re: sorting months according to fiscal year
  In-Reply-To: <1314019633187-4723409.post@n5.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox