Re: Week to date function

Поиск
Список
Период
Сортировка
От Ireneusz Pluta
Тема Re: Week to date function
Дата
Msg-id 4BAC9EC1.7010708@wp.pl
обсуждение исходный текст
Ответ на Re: Week to date function  (Sergey Konoplev <gray.ru@gmail.com>)
Список pgsql-sql
Sergey Konoplev pisze:
>> CREATE OR REPLACE FUNCTION your_week2date(double precision, double
>> precision) RETURNS SETOF date
>> AS
>> $_$
>> SELECT  day
>> FROM (
>>   SELECT  (
>>               date_trunc('week', ($1::text||'-01-01')::date)
>>               + ($2::text||' week')::interval
>>               + ( d::text||'  day')::interval
>>           )::date  AS  day
>>   FROM    generate_series(0, 6) AS d
>> )   alias
>> WHERE   to_char(day, 'IYYY')::integer = $1
>> ORDER
>> BY      1
>> $_$
>> LANGUAGE SQL
>> IMMUTABLE
>>     
>
> I think it is better to use date_part('year', day) instead of
> to_char(...).
this might cut first or last week in the year, like this:


SELECT your_week2date(2009, 52) ;your_week2date
----------------2009-12-282009-12-292009-12-302009-12-312010-01-01   cut2010-01-02   cut2010-01-03   cut
(7 rows)

which is not what I want when playing with isoweeks.
>  And may be it is worth to do raise exception when
> incorrect week specified.
>   
but, maybe, controlled by an additonal parameter saying if one prefers 
to have exception or rather an empty resultset



В списке pgsql-sql по дате отправления:

Предыдущее
От: Sergey Konoplev
Дата:
Сообщение: Re: Week to date function
Следующее
От: Jorge Godoy
Дата:
Сообщение: Re: Week to date function