From: | Jasen Betts <jasen(at)xnet(dot)co(dot)nz> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Confused about writing this stored procedure/method. |
Date: | 2011-08-23 10:14:38 |
Message-ID: | j2vuie$tte$2@reversiblemaps.ath.cx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 2011-08-22, JavaNoobie <vivek(dot)mv(at)enzentech(dot)com> wrote:
> Hi All,
> I'm trying to write a stored procedure /function to re-order a set of
> calendar months.I have a set of calendar months stored from January to
> December in my tables. And as of now when I do order by on this column ,
> the data is ordered alphabetically , starting April, august etc. and so on
> I want to order these months starting from April through March in order to
> sync with the financial calendar . I'm trying to write a stored procedure to
> do the same (I'm not aware of any other method that Postgres offers this
> reordering , if there's any , please do let me know!).
order by (case month when 'January' then 1 when 'February' then 2
...[I'm too lazy to type the rest]... when 'December' then 12 end)
get the idea? (except change the numbers to match financial calendar)
you can index on that expression too
if you have them as numbers instead of words you can use an array
instead of the case.
For as task like this an SQL function may be more efficient than a
PLPGSQL function.
--
⚂⚃ 100% natural
From | Date | Subject | |
---|---|---|---|
Next Message | Samuel Gendler | 2011-08-23 10:15:54 | Re: exclusion constraint for ranges of IP |
Previous Message | Julien Cigar | 2011-08-23 10:03:43 | WITH RECURSIVE question |