SELECT
monthperiod.*,
array_to_string(ARRAY
(SELECT (d + 1)::varchar(20)
FROM
generate_series(0,30) d
WHERE
monthperiod.start_date + (d || ' day')::interval
BETWEEN
monthperiod.start_date
AND
monthperiod.end_date), ','
) AS thedays
FROM
(SELECT
(n + 1) AS mnum,
TRIM(to_char(date '2007-01-01' + (n || ' month')::interval, 'Mon')) AS short_mname,
TRIM(to_char(date '2007-01-01' + (n || ' month')::interval, 'Month')) AS long_mname,
date '2007-01-01' + (n || ' month')::interval AS start_date,
date '2007-01-01' + ((n + 1) || ' month')::interval + - '1 day'::interval AS end_date
FROM
generate_series(0,11) n) AS monthperiod
Ref : http://www.postgresonline.com/special_feature.php?sf_name=postgresql83_cheatsheet&outputformat=html
monthperiod.*,
array_to_string(ARRAY
(SELECT (d + 1)::varchar(20)
FROM
generate_series(0,30) d
WHERE
monthperiod.start_date + (d || ' day')::interval
BETWEEN
monthperiod.start_date
AND
monthperiod.end_date), ','
) AS thedays
FROM
(SELECT
(n + 1) AS mnum,
TRIM(to_char(date '2007-01-01' + (n || ' month')::interval, 'Mon')) AS short_mname,
TRIM(to_char(date '2007-01-01' + (n || ' month')::interval, 'Month')) AS long_mname,
date '2007-01-01' + (n || ' month')::interval AS start_date,
date '2007-01-01' + ((n + 1) || ' month')::interval + - '1 day'::interval AS end_date
FROM
generate_series(0,11) n) AS monthperiod
Ref : http://www.postgresonline.com/special_feature.php?sf_name=postgresql83_cheatsheet&outputformat=html
No comments:
Post a Comment