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-28
2009-12-29
2009-12-30
2009-12-31
2010-01-01   cut
2010-01-02   cut
2010-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


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply via email to