pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Work hours?
Date: Tue, 27 Aug 2019 23:56:27 -0500
Message-ID: <76ffd2ba-9e26-c3b2-b310-64c423b1b222@gmail.com> (raw)
In-Reply-To: <CAFNqd5X+8pzP50iM++RGNmO-_crJoh8fOttZDE4twt1gqsEhMQ@mail.gmail.com>
References: <20190827222741.GB19306@panix.com>
	<CAFNqd5X+8pzP50iM++RGNmO-_crJoh8fOttZDE4twt1gqsEhMQ@mail.gmail.com>

On 8/27/19 10:22 PM, Christopher Browne wrote:
>
>
> On Tue, Aug 27, 2019, 6:27 PM stan <stanb@panix.com 
> <mailto:stanb@panix.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.

We did something similar to that, except all the columns were in one single 
table.  It wasn't a data warehouse, though: the RDBMS we used could be 
coerced into using a date index when large ranges were needed in detail 
tables by joining it to T_CALENDAR, and doing the range filter on T_CALENDAR.

-- 
Angular momentum makes the world go 'round.

view thread (14+ messages)  latest in thread

Message-ID: <76ffd2ba-9e26-c3b2-b310-64c423b1b222@gmail.com>
Permalink:  ../76ffd2ba-9e26-c3b2-b310-64c423b1b222@gmail.com/
Also on:    postgresql.org/message-id/76ffd2ba-9e26-c3b2-b310-64c423b1b222@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Work hours?
  In-Reply-To: <76ffd2ba-9e26-c3b2-b310-64c423b1b222@gmail.com>
  References: <20190827222741.GB19306@panix.com> <CAFNqd5X+8pzP50iM++RGNmO-_crJoh8fOttZDE4twt1gqsEhMQ@mail.gmail.com> <76ffd2ba-9e26-c3b2-b310-64c423b1b222@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox