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 1i2kdT-0001CJ-EX for pgsql-general@arkaria.postgresql.org; Tue, 27 Aug 2019 23:12:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i2kdR-00081g-9Z for pgsql-general@arkaria.postgresql.org; Tue, 27 Aug 2019 23:12:21 +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 1i2kdQ-00081Y-Ti for pgsql-general@lists.postgresql.org; Tue, 27 Aug 2019 23:12:21 +0000 Received: from mail-ot1-x329.google.com ([2607:f8b0:4864:20::329]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2kdO-0008Fa-PQ for pgsql-general@lists.postgresql.org; Tue, 27 Aug 2019 23:12:20 +0000 Received: by mail-ot1-x329.google.com with SMTP id k18so896146otr.3 for ; Tue, 27 Aug 2019 16:12:18 -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-transfer-encoding:content-language; bh=8y9MMIODtvu0K1Oo6m03OVyHXECAKRTgQEw2eq4Idnw=; b=Q0BpaX/2uX8ib5tz9rZUtI7l5FX7Vt0VSd1cZAlvDc+H/X5ipanKozNhwjJmSwazND 5VBNArobgfgAVx8JcFN7Up/2/Y81iS5l8y3e6+voJHMWhLm9FzNqBAa1KescoImsHqgH KFzVbrXa1DS46QIRBhonpE3zm68cmdj+hJoY1ozcWOAqcJWhR1mVbaMYrHfZfhwBUrM1 MwgKHTxz2IaURwIGZa5BNVfHlfBsKGM1CGtdWbPTYvLlvCUucL+EsE9pt0wQUX3p9AjO VTdOnCnjn12fbs99jdiAU+362f9nkofLjbEI5Pk3k0cQVXhMGUtTNRV8H8o9g2XbbuSv AXPg== 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-transfer-encoding :content-language; bh=8y9MMIODtvu0K1Oo6m03OVyHXECAKRTgQEw2eq4Idnw=; b=Vlf47m1lMkm/G0teT0TjuMunKSNz8jzb+tNaaXHQRSj0WRUg1hrNWo9vqJCAXINqlc 6r0WEQYdkL3clYXsHxg/c9SgkcY/mJ1pq+Q4Gg1vhzhlRxtgX5lToj5tPqKAC2nxP2ek 2hICtyUyQqRJ6tXxaB+JHH7M28aqa85eyzbCEsR3BKXkt/0P2yjKTeNkl7Ujgu2ZJjYb CTD0y4/fxhZ5CQenEwxc3ozLaUSprD4bT2JhbDSG71ZvleTmQXQrkmEvaiakYTB5Ntqw 6I61PhAID/52FerXXRENhSykDD++4+5DwDHJ2jGEXkhQizNDi2FRX/32f1U0eUMQ4xTq I3mA== X-Gm-Message-State: APjAAAXVQAMjaSd49ZWnrb6C1GZljHmPDhd7FYscMf6E5fRM1j98TcK2 yzKmEVhuYlWfy4AA12QvsBP9nXMuZniwkg== X-Google-Smtp-Source: APXvYqxkL7a+wF2EqK9spomlfs6A410YQf5kvop4VQNt+/DPKKqLT+boRVjfvnVKcHxKuItt28qlDQ== X-Received: by 2002:a05:6830:12:: with SMTP id c18mr891632otp.116.1566946182869; Tue, 27 Aug 2019 15:49:42 -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 n32sm303973otn.61.2019.08.27.15.49.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Aug 2019 15:49:42 -0700 (PDT) Subject: Re: Work hours? To: pgsql-general@lists.postgresql.org References: <20190827222741.GB19306@panix.com> From: Ron Message-ID: <5105f7f5-cf86-eab5-ff1a-5283ca271990@gmail.com> Date: Tue, 27 Aug 2019 17:49:41 -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: <20190827222741.GB19306@panix.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 8/27/19 5: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? I haven't tried this, but should point you in the right direction: SELECT SUM(EXTRACT(DOW FROM the_date)) * 8.0 AS work_week_hours FROM some_table WHERE EXTRACT(DOW FROM the_date) BETWEEN 1 and 5   AND the_date BETWEEN '2019-07-01' AND '2019-07-31 23:59:59'; It'll probably (nay, almost definitely) seq scan. -- Angular momentum makes the world go 'round.