Re: Confused about writing this stored procedure/method.

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: Confused about writing this stored procedure/method.
Дата
Msg-id j2vuie$tte$2@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на Confused about writing this stored procedure/method.  (JavaNoobie <vivek.mv@enzentech.com>)
Список 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 по дате отправления:

Предыдущее
От: Samuel Gendler
Дата:
Сообщение: Re: exclusion constraint for ranges of IP
Следующее
От: Jasen Betts
Дата:
Сообщение: Re: exclusion constraint for ranges of IP