Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2q5l-0007wW-00 for pgsql-general@arkaria.postgresql.org; Wed, 28 Aug 2019 05:01:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i2q5h-0007FF-96 for pgsql-general@arkaria.postgresql.org; Wed, 28 Aug 2019 05:01:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2q5g-0007F8-Sz for pgsql-general@lists.postgresql.org; Wed, 28 Aug 2019 05:01:53 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2q5d-0003rS-Tv for pgsql-general@lists.postgresql.org; Wed, 28 Aug 2019 05:01:52 +0000 Received: by mail-ot1-x333.google.com with SMTP id c7so1533984otp.1 for ; Tue, 27 Aug 2019 22:01:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=rWlI3hlT/jJBhKU/DIYxbe1SHhUcmI4UB30Y30JqIn4=; b=tgfU5N704sKXqmdaPT+M4c9WOQtm92Nmx5pXNtYb9HbGGVKYVNqs2YyJ8WD5J4KJcW bUGZdxmFnnF5OfdvOXuBW9xroDks51dwTx3alXzF1rfPGrPHsSv389DX1MSOif758Z6Z zZOhSzW7W9Xjh8QP2RoBhqOJl0Nzw2r9jRpnX1iUzfK3CkyOhEaZzfTJYYPkmIEoH60F fxfou5YzIemVwGlE0DY/g4FMQwhqIbSBBJRtd5DFPPTBhD5+m/jmvxx0cAXS30tiPmM3 iVbgE3AXkplhyaVyNnfuvVRYJxj/k5KqGyeRYW8zqQbUewKcLCiMn0qHIipRDxjKrqYF 1Naw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=rWlI3hlT/jJBhKU/DIYxbe1SHhUcmI4UB30Y30JqIn4=; b=HmhA77E+5+u6xH5XqSExhOPwat+UvUmfOzJ9h1TkGh+/9bdxWJ+yovbtGycFhQirIi citVSqdKMejzB5ZKPgm9HAWO8E0b4Vv9VLfy4kdWCdfkw+evWt5tOfPT2wVncVAMkaE7 A0KBxv48bk2Vbg8P8HKveaa1eamUNHYXnlMiCJDvFIBiRlTkSnKe8zR05EzCe7a88pQe DVkbt8okj+K7aVJQQgSBOBwoCd5XavUsqv0NEeW72CAa8Fwp+UuM+nudx7lOaqLe3MJZ uMZRxVnECunn9lxFFeZUbM5AJGqft6dvifpRfCrUuiS0+g139IC4vSgG27zE3ysOs7LP kwJQ== X-Gm-Message-State: APjAAAXmVKiSMtIjCwBSioozj/h5OZHy/nTuzD8MSeJOtvoTo1gonrNm l0vapLvyf3QwkSOp5/Zhcbj2A/+9ZdFGUA== X-Google-Smtp-Source: APXvYqxNEtt2S0eI5SeS7xmJguh4hYmZd8HHFOvXgNguLLZRWvDpO+2UUsfztrmWaEzUe0im6NWjfQ== X-Received: by 2002:a05:6830:134a:: with SMTP id r10mr1834754otq.17.1566968189252; Tue, 27 Aug 2019 21:56:29 -0700 (PDT) Received: from [192.168.1.10] (ip70-186-126-197.no.no.cox.net. [70.186.126.197]) by smtp.googlemail.com with ESMTPSA id y15sm504748oix.28.2019.08.27.21.56.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Aug 2019 21:56:28 -0700 (PDT) Subject: Re: Work hours? To: pgsql-general@lists.postgresql.org References: <20190827222741.GB19306@panix.com> From: Ron Message-ID: <76ffd2ba-9e26-c3b2-b310-64c423b1b222@gmail.com> Date: Tue, 27 Aug 2019 23:56:27 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------0ED1A22358A0D2294A29C318" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------0ED1A22358A0D2294A29C318 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 8/27/19 10:22 PM, Christopher Browne wrote: > > > On Tue, Aug 27, 2019, 6:27 PM stan > 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. --------------0ED1A22358A0D2294A29C318 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 8/27/19 10:22 PM, Christopher Browne wrote:


On Tue, Aug 27, 2019, 6:27 PM stan <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.


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.
--------------0ED1A22358A0D2294A29C318--