Feature Request: "generate_series(DATE, DATE)" and "generate_series(DATE, DATE, INT)"

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Feature Request: "generate_series(DATE, DATE)" and "generate_series(DATE, DATE, INT)"
Date: 2009-10-12 22:44:14
Message-ID: m3eip8nsg1.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

as discussed on -general, I'd like to propose that Post-
greSQL provides "generate_series(DATE, DATE)" and
"generate_series(DATE, DATE, INT)" functions by default.

They are merely syntactic sugar for
"generate_series($1::TIMESTAMP, $2::TIMESTAMP[,
'$3 days'::INTERVAL])::DATE" and can be used whenever a
range of dates is used, e. g. to ("LEFT JOIN"ly) group rows
by calendar date.

Non-C implementations would be (credits to Sam Mason):

| CREATE FUNCTION generate_series(DATE, DATE)
| RETURNS SETOF DATE
| IMMUTABLE LANGUAGE SQL AS
| $$SELECT generate_series($1::TIMESTAMP, $2::TIMESTAMP, '1 day'::INTERVAL)::DATE;$$;
| CREATE FUNCTION generate_series(DATE, DATE, INT)
| RETURNS SETOF DATE
| IMMUTABLE LANGUAGE SQL AS
| $$SELECT generate_series($1::TIMESTAMP, $2::TIMESTAMP, ($3 || ' days')::INTERVAL)::DATE;$$;

TIA,
Tim

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-10-12 23:45:46 Re: GRANT ON ALL IN schema
Previous Message Tom Lane 2009-10-12 20:41:04 Re: GRANT ON ALL IN schema