From: | Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Work hours? |
Date: | 2019-08-29 06:24:34 |
Message-ID: | 2b160f5c-4315-734b-1550-ddb64cec46be@archidevsys.co.nz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 28/08/2019 15:22, Christopher Browne wrote:
>
>
> On Tue, Aug 27, 2019, 6:27 PM stan <stanb(at)panix(dot)com
> <mailto:stanb(at)panix(dot)com>> wrote:
>
> I am just starting to explore the power of PostgreSQL's time and date
> functionality. I must say they seem very powerful.
>
> I need to write a function that, given a month, and a year as
> input returns
> the "work hours" in that month. In other words something like
>
> 8 * the count of all days in the range Monday to Friday) within that
> calendar month.
>
> Any thoughts as to the best way to approach this?
>
>
> In data warehouse applications, they have the habit of creating tables
> that have various interesting attributes about dates.
>
> https://medium.com/@duffn/creating-a-date-dimension-table-in-postgresql-af3f8e2941ac
>
> I'd be inclined to solve this by defining various useful sets of
> dates; you might then attach relevant attributes to a dimension table
> like the d_date table in the article.
>
> - a table with all weekdays (say, Monday to Friday)
>
> - a table listing statutory holidays that likely need to be excluded
>
> These are going to be small tables even if you put 10 years worth of
> dates in it.
>
[...]
You don't need a whole table for weekdays. You can easily calculate the
number of weekdays simply from knowing the first day of the month and
how many days in a month.
Cheers,
Gavin
From | Date | Subject | |
---|---|---|---|
Next Message | Luca Ferrari | 2019-08-29 06:42:53 | Re: Question about password character in ECPG's connection string |
Previous Message | Laurenz Albe | 2019-08-28 20:37:34 | Re: wal_level logical for streaming replication |