Re: Confused about writing this stored procedure/method. - Mailing list pgsql-sql

From Jasen Betts
Subject Re: Confused about writing this stored procedure/method.
Date
Msg-id j2vuie$tte$2@reversiblemaps.ath.cx
Whole thread Raw
In response to Confused about writing this stored procedure/method.  (JavaNoobie <vivek.mv@enzentech.com>)
List pgsql-sql
On 2011-08-22, JavaNoobie <vivek.mv@enzentech.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



pgsql-sql by date:

Previous
From: Samuel Gendler
Date:
Subject: Re: exclusion constraint for ranges of IP
Next
From: Jasen Betts
Date:
Subject: Re: exclusion constraint for ranges of IP